Skip to content

Instantly share code, notes, and snippets.

View thelissimus's full-sized avatar
💢

kei thelissimus

💢
View GitHub Profile
module Main (main) where
import Control.Monad.State
main :: IO ()
main = print . solve =<< readFile "input.txt"
data Dir = L Int | R Int
parseDir :: String -> Dir
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE UnboxedTuples #-}
module RelatedPostGen (module RelatedPostGen) where
import Control.DeepSeq (NFData)
import Control.Monad (when)
import Data.Aeson.TH
{-# LANGUAGE ApplicativeDo #-}
module Main (main) where
import Data.List
import Options.Applicative
import System.Exit
data Cmd
= Query QueryOpts
module Named
( Named
, type (~~)
, name
) where
import Data.Coerce
import The
newtype Named name a = MkNamed a
@thelissimus
thelissimus / main.ml
Created September 24, 2025 15:43
Naive SAT-solver in OC*ml 🤮
(* propositional logic *)
(* https://t.me/keistash/148 *)
type expr
= Lit of bool (* base case *)
| Var of string (* base case *)
| Not of expr
| And of expr * expr
| Or of expr * expr
@thelissimus
thelissimus / FORMAL.md
Last active August 21, 2025 18:28
Formal Methods Pitch (19.09.2024)

Problems:

  • Even though we specify what is needed for the front-end with API and types we cannot enforce nor specify the business logic.
  • We cannot be sure that our understanding of the business logic doesn't have flaws in the first place.
  • We cannot enforce invariants.
  • We cannot be sure that our implementation doesn't have bugs.

All we will have is a husk of the API with no value at all.

Solution

def headOpt (xs : List α) : Option α :=
match xs with
| x :: _ => some x
| [] => none -- need to introduce `Option` to handle the empty list case
def head (xs : List α) (h : xs ≠ []) : α :=
match xs with
| x :: _ => x
-- no need to handle empty list case as it is impossible
data Graph a
= Empty
| Vertex a
| Overlay (Graph a) (Graph a)
| Connect (Graph a) (Graph a)
deriving stock (Show)
instance (Num a) => Num (Graph a) where
fromInteger = Vertex . fromInteger
(+) = Overlay
@thelissimus
thelissimus / Label.hs
Created April 12, 2025 01:07
Labeling traversables.
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE DerivingStrategies #-}
import Control.Monad.State
data Tree a = Node (Tree a) a (Tree a) | Leaf
deriving stock (Show, Functor, Foldable, Traversable)
data Rose a = Rose a [Rose a]
deriving stock (Show, Functor, Foldable, Traversable)
module Lib (module Lib) where
import Control.Monad (ap, (>=>))
----------------------------------------------------------------------------------------------------
data Coroutine i o a
= Await (i -> Coroutine i o a)
| Yield o (Coroutine i o a)
| Done a