Skip to content

Instantly share code, notes, and snippets.

@qexat
qexat / jekyll_idea.md
Last active April 16, 2025 13:23
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
;;
@qexat
qexat / Cygnus2.ml
Created March 12, 2025 19:16
something with inductive types or whatever
type inhabited = Inhabited
module Hole = struct
(* Discriminator for Done *)
type 'ty value = Value of 'ty
(* Discriminator for Falling *)
type nonterm = Nonterm
type 'value t =
@qexat
qexat / factorial.neige.ml
Last active February 3, 2025 21:31
a simple neige program
#!/usr/bin/env -S neige run
extend Nat with module
# This version does not care about a leading zero
let parse_decimal_digits : String -> List Nat =
let tailrec string acc =
match string with
| "" -> acc
| ('0' .. '9' as first) :: rest ->
let digit = Char.code_point_of first - Char.digit_offset in
@qexat
qexat / is_odd_cursed.py
Last active March 29, 2025 20:49
Cursed, coinductive and tail-recursive implementation of `is_odd`. Time complexity is O(n) when n is odd ; otherwise, it does not terminate (up to the machine's physical limits).
# ruff: noqa: S101, PLR6301, RUF002
"""
Cursed implementation of `is_odd`.
It relies on two interesting properties. Firstly, the set formed
by the difference of consecutive squares is the odd members of
ℕ - let's call this set ℕ_odd.
Secondly, the negative integers are symmetric to their positive
counterparts with respect to oddness. Differently put, negating
a number preserves the fact that it is odd.
@qexat
qexat / Scopes_objects_and_explicits.ml
Created January 27, 2025 12:11
scopes: objects and explicits
(* we start by setting up a global scope.
`setup` is a special function that handles all we need behind
the scenes. `$global` is a macro that gets substituted with
the scope ID from the meta-environment mapping (ID -> scope) *)
$global -> setup ()
(* `let` is an applicative statement that handles intro and
substitution in the specified scope *)
let($global) n := 3
@qexat
qexat / nat.jml
Last active January 27, 2025 09:28
public Nat -> type
| O : Nat
| S : Nat -> Nat
public successor -> fun (n : Nat) : Nat => S n
public predecessor -> fun (S n : Nat) : Nat => n
public n + m ->
split n, m into
| _, O -> n
@qexat
qexat / equality.hs
Created January 4, 2025 23:35
idk haskell stuff
{-# LANGUAGE MonoLocalBinds #-}
module Main where
class Relation r a b
class Relation r a a => Reflexivity r a where
reflexivity :: r a a
class Relation r a b => Symmetry r a b where
@qexat
qexat / Ptr.ml
Created December 12, 2024 09:26
Ptr.ml
module Ptr = struct
type 'a t
external create : 'a -> 'a t = "%makemutable"
external get_value : 'a t -> 'a = "%field0"
external of_ref : 'a ref -> 'a t = "%identity"
let of_int : int -> 'a t = function
| i -> Obj.magic (i / 2)
;;
@qexat
qexat / Lexer.ml
Created December 4, 2024 12:49
(munii) lexers!
module Char = struct
include Char
let is_alpha : t -> bool = function
| 'A' .. 'Z' | 'a' .. 'z' | '_' -> true
| _ -> false
;;
let is_digit : t -> bool = function
| '0' .. '9' -> true