Skip to content

Instantly share code, notes, and snippets.

@mb64
mb64 / t.elpi
Last active October 12, 2021 21:03
"complete and easy" (mostly), in ELPI
kind ty type.
type tunit ty.
type tfun ty -> ty -> ty.
type tall (ty -> ty) -> ty.
kind tm type.
type unit tm.
type app tm -> tm -> tm.
@mb64
mb64 / tychk.ml
Last active November 15, 2025 17:34
Bidirectional typechecking for higher-rank polymorphism in OCaml, without polymorphic subtyping
(* Compile with:
$ ocamlfind ocamlc -package angstrom,stdio -linkpkg tychk.ml -o tychk
Example use:
$ ./tychk <<EOF
> let f = (fun x -> x) : forall a. a -> a
> in f f
> EOF
input : forall a. a -> a
*)
@mb64
mb64 / generate.sh
Created November 21, 2021 06:10
All the responses to the free-response parts of the Haskell survey
#!/bin/bash
# Source: https://taylor.fausak.me/2021/11/16/haskell-survey-results
wget https://taylor.fausak.me/static/pages/2021-state-of-haskell-survey-results.json.zip
unzip 2021-state-of-haskell-survey-results.json.zip
echo "Question: If you wanted to convince someone to use Haskell, what would you say?" > q1-convince.txt
echo "---" >> q1-convince.txt
jq -r 'map(.s9q0 | .[]?) | join("\n---\n")' < 2021-state-of-haskell-survey-results.json >> q1-convince.txt
@mb64
mb64 / nbe.agda
Created January 29, 2022 20:59
Normalization by Evaluation for the simply typed lambda calculus, in Agda
-- Normalization by Evaluation for STLC, in Agda
--
-- Partially based on "NbE for CBPV and polarized lambda calculus" (Abel, 2019)
open import Function
infixr 5 _⇒_
infixl 4 _,_
infix 2 _⊃_
@mb64
mb64 / hm_with_kinds.ml
Created February 13, 2022 00:16
Hindley-Milner type checking with higher-kinded types, in OCaml
type name = string
module AST = struct
type ty =
| TFun of ty * ty
| TNamed of string
| TApp of ty * ty
type exp =
| Annot of exp * ty
@mb64
mb64 / mltt.ml
Last active October 16, 2024 17:59
Very simple typechecker for MLTT
(* Typechecker for MLTT with a universe hierarchy *)
(* Build with: ocamlfind ocamlc -package angstrom,stdio -linkpkg mltt.ml -o mltt *)
type name = string
module AST = struct
type tm =
| Var of name
| U of int
| Pi of name * ty * ty
| Annot of tm * ty
@mb64
mb64 / dpll_t.ml
Last active March 26, 2022 06:09
Itty bitty SMT solver: DPLL(T) where T = equality. Likely buggy
(* Itty bitty SMT solver: DPLL(T) where T = equality *)
(*
# let x, y = 0, 1 (* integer variable IDs *) ;;
# let prob = SMT.new_problem 2 (* 2 for two variables *) ;;
# let b = SMT.new_bool prob;;
# SMT.add_clause prob [b; SMT.eq prob x y];
SMT.add_clause prob [SMT.not b];
SMT.solve prob;;
- : SMT.response = SMT.SAT
# SMT.add_clause prob [SMT.not (SMT.eq prob x y)];