Skip to content

Instantly share code, notes, and snippets.

@qexat
qexat / SGR_stack_machine_poc.ml
Created December 11, 2025 14:56
proof of concept for a basic SGR stack machine
(* SGR stack machine *)
module Color = struct
type t =
| Basic of int
| Rgb of int * int * int
end
module Style = struct
type t =
@qexat
qexat / symbols.txt
Last active December 10, 2025 20:12
A
ABC
ABCMeta
ACCESS_COPY
ACCESS_DEFAULT
ACCESS_READ
ACCESS_WRITE
ACK
ACTIVE
ADDITEMS
@qexat
qexat / Nilable.ml
Last active November 14, 2025 21:21
this is the future jane street wants. #NoToNil #protest #Option4Ever #foryou #foryoupage
type nil = Nil
(* This version is unsafe because it makes the assumption that index >= 0. *)
let rec get_unsafe : 'a. at:int -> from:'a list -> 'a | nil =
fun ~at:index ~from:list ->
match list with
| [] -> Nil
| first :: _ when index = 0 -> first
| _ :: rest -> get_unsafe ~at:(index - 1) ~from:rest
(* -*- Interfaces -*- *)
module type ORDERED = sig
type ('a, 'b) t
end
module type LINEAR = sig
include ORDERED
val exchange : 'a 'b. ('a, 'b) t -> ('b, 'a) t
@qexat
qexat / deez_nats.py
Created October 31, 2025 11:06
oh my god lexa will you ever stop defining peano integers in every language on earth a thousand times AND differently every time like seriously im starting to get worried for your mental health i mean what even is your goal with that what do you gain from it because i dont see it and look im not trying to be dismissive or anything but you could …
import enum
import typing
class Nat(enum.Enum):
O = enum.auto()
S = enum.auto()
type nat = typing.Literal[Nat.O] | tuple[typing.Literal[Nat.S], nat]
O = Nat.O
@qexat
qexat / Hoskaml.ml
Last active October 26, 2025 11:33
mmm... perform_io...
module Util = struct
let ( let*? ) = Option.bind
let ( let*! ) = Result.bind
let ( let@ ) = ( @@ )
let ( *> ) f g x = g (f x)
let curry = ( @@ )
let curry2 f a b = f (a, b)
let curry3 f a b c = f (a, b, c)
let ( let|> ) a k = a (curry k)
let ( let||> ) a k = a (curry2 k)
@qexat
qexat / Or_gadt.ml
Created October 16, 2025 11:31
disjunction funsies with GADTs
type left = private Left_tag
type right = private Right_tag
type ('ctr, 'left, 'right) t =
| Left : 'a 'b. 'a -> (left, 'a, 'b) t
| Right : 'a 'b. 'b -> (right, 'a, 'b) t
let introduction_left : type a b. a -> (left, a, b) t =
fun a -> Left a
@qexat
qexat / ramblings.hs
Created October 7, 2025 07:45
functor ramblings in pseudo-haskell. unfortunately perfect parsing requires multicategories
e ::= x
| '(' e ')'
| e e
| 'λ' x '.' e
---------------------------------------------------------------
_&>_ a b = a (a b)
or_elim = (a c) (b c) a b c
or_elim f _ (Left a) = f a
or_elim _ g (Right b) = g b
@qexat
qexat / README.md
Created September 26, 2025 07:21
static verification of equality in python! try it on a typechecker like pyright
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE UndecidableSuperClasses #-}
import Data.Kind
class (c a, c b) => SafeCoercible (c :: Type -> Constraint) a b | c a -> b where
safeCoerce :: a -> b
instance SafeCoercible Num Int Float where