Skip to content

Instantly share code, notes, and snippets.

@qexat
qexat / Visitor.ml
Created July 3, 2025 13:30
goofy implementation of λ-calculus
let ( let+ ) = Option.bind
module Expr = struct
type app = A
type fun' = F
type name = N
type 'variant reducible = A : app reducible
type 'variant irreducible =
| F : fun' irreducible
@qexat
qexat / What_the_type.ml
Last active July 1, 2025 15:00
what the fuck? you can just do this????
module type TYPE = sig
type t
end
type 't module' = (module TYPE with type t = 't)
type 'a first = 'b constraint 'a = 'b * _
type 'a second = 'c constraint 'a = _ * 'c
module Runtype = struct
type 'a t =
@qexat
qexat / Logfuck.ml
Last active June 26, 2025 22:28
logfuck toplevel
let get_char () =
let attr = Unix.tcgetattr Unix.stdin in
let () =
Unix.tcsetattr
Unix.stdin
Unix.TCSADRAIN
{ attr with Unix.c_icanon = false }
in
let res = input_byte stdin in
Unix.tcsetattr Unix.stdin Unix.TCSADRAIN attr;
@qexat
qexat / grader.ml
Created June 13, 2025 14:38
some parser combinator draft
module Option = struct
include Option
let or_else : type item. (unit -> item t) -> item t -> item t =
fun rightf left ->
match left with
| None -> rightf ()
| _ -> left
;;
@qexat
qexat / amy.grammar
Last active June 6, 2025 14:52
Draft grammar for the Amy programming language
tokens:
INFINITY ≔ '∞'
ZERO ≔ '0'
ONE ≔ '1'
NONZERO ≔ /[1-9][0-9]*/
QUESTION_MARK ≔ '?'
BANG ≔ '!'
NAME ≔ /[A-Za-z_][A-Za-z0-9_']*/
CONTAINS ≔ '∋'
@qexat
qexat / Eqw.v
Last active June 5, 2025 10:51
Equivalence relation up to some isomorphism f, with some properties related to equality.
Require Import Utf8.
(** [Eqw f x y] represents the equivalence x y up to an isomorphism f. *)
Inductive Eqw {A B : Type} (f : A → B) : A → A → Prop :=
| Refl (x y : A) : f x = f y → Eqw f x y.
(** Notation for convenience. Same level as equality. *)
Notation "x = y 'up' 'to' f" := (Eqw f x y).
(** Utilitary functions for the theorems below. *)
@qexat
qexat / levelled_term.v
Created May 12, 2025 15:36
levelled term using a GADT (rocq)
Require Import String.
Inductive Term : nat -> Type :=
| App : forall {n m : nat}, Term (S n) -> Term m -> Term (n + m)
| Fun : forall {n : nat}, Term 0 -> Term n -> Term (S n)
| Var : string -> Term 0.
@qexat
qexat / CT.md
Last active May 15, 2025 16:08
a simple type system with support for (co)cartesian types

Notes

(Co)Cartesian Types

Definitions

A cartesian type is a generalized type product where one inhabitant, called origin is common to all the types involved (called axes). A cocartesian type is a generalized type sum with a common origin to all axes.

That is, A * ... * Z is a cartesian type if there exists one inhabitant i common to every axis — i_A = i_B = ... = i_Z.

@qexat
qexat / jekyll_idea.md
Last active May 15, 2025 19:41
jekyll: a hyper-declarative, statically-typed programming language around environment manipulation

jekyll: a hyper-declarative, statically-typed programming language around environment manipulation

# x is introduced to the environment
{ ..?e } → { x := 3 ; ..?e }
# y too ; ?e is not the same row variable as the one above
{ ..?e } → { y := 5 ; ..?e }
# matching the current context on one that contains an x and a y
# which allows us to add them to introduce y
{ x ; y ; ..?e } → { z := x + y ; ..?e } 
@qexat
qexat / Intervals.ml
Created April 14, 2025 16:45
polymorphic intervals with abstract algebra and category theory
let ( or ) option default = Option.value option ~default
module Int = struct
include Int
let compare i1 i2 =
let as_int = compare i1 i2 in
if as_int > 0 then `Greater else if as_int < 0 then `Less else `Equal
;;