Skip to content

Instantly share code, notes, and snippets.

@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)];
@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 / 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 / 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 / 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 / tychk.ml
Last active November 13, 2024 07:04
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 / 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 / PowerSeries.agda
Last active April 7, 2021 23:00
A proof that formal power series over an arbitrary commutative ring form a commutative ring, formalized in Agda using guarded coinduction.
{-# OPTIONS --guardedness --safe #-}
open import Data.Product
open import Function using (_$_)
open import Relation.Binary using (IsEquivalence)
open import Algebra
open import Relation.Binary.Definitions
import Relation.Binary.Reasoning.Setoid as ≈-Reasoning
open import Tactic.RingSolver using (solve-∀)
@mb64
mb64 / heap_bench.sml
Created March 13, 2021 00:27
Heap benchmarks in MLton
(** A small benchmark for heap implementations
*
* Task: (mutably) sort an array, using heap sort
* Implementations:
* - BinaryHeap, a simple binary heap implemented with mutable array operations
* - PairingHeap, Okazaki's strict amortized pairing heap
* - SplayHeap, Okazaki's strict amortized splay heap
* - BinomialHeap, Okazaki's strict amortized binomial heap
* - LeftistHeap, Okazaki's strict rank-based leftist heap
*
@mb64
mb64 / Prolog.hs
Created January 31, 2021 02:17
A simple, readable Prolog interpreter in Haskell
{-# LANGUAGE ImportQualifiedPost, BlockArguments #-}
module Main where
import Control.Applicative
import Control.Monad
import Control.Monad.RWS
import Data.Char
import Data.Foldable
import Data.List
import Data.Set qualified as Set