Skip to content

Instantly share code, notes, and snippets.

@Guest0x0
Guest0x0 / ANF-with-joint-point.ml
Created November 18, 2022 12:42
ANF transformation with joint point for branching, using higher order reference cell
module Src = struct
type expr =
| Int of int
| Var of string
| Op of string * expr * expr
| Let of string * expr * expr
| If of expr * expr * expr
end
@Guest0x0
Guest0x0 / ANF-with-joint-point.ml
Created November 18, 2022 12:46
ANF transformation with joint point optimization for branching, using explicit CPS
module Src = struct
type expr =
| Int of int
| Var of string
| Op of string * expr * expr
| Let of string * expr * expr
| If of expr * expr * expr
end
@Guest0x0
Guest0x0 / minimal-PM.ml
Last active July 7, 2023 02:19
a minimal pattern matching compiler demo
(* a minimal pattern-matching compiler *)
(* use integer as variable for easy generation *)
type var = int
type typename = string
type constructor = string
type typ =
@Guest0x0
Guest0x0 / minimal-MLTT.ml
Last active May 14, 2025 12:49
minimal MLTT implementation step-by-step
(* 这是我(预期,亦或是已经)在 ∞-type càfe summer school 上做的 talk,
"从零教你手把手实现一个 MLTT 类型检查器"
的内容稿。本 talk 计划以现场边讲解边手写代码的方式实现,
所以虽然这份内容稿会尽量尝试还原 talk 的思路和逻辑,
它的内容可能会与实际的 talk 有出入,建议有条件的人直接去听 talk 本身 *)
(* 本次 talk 将会使用 OCaml 来实现一个 MLTT 类型检查器。
你可能不会写 OCaml,但这没有关系。本次 talk 只会使用以下的功能:
@Guest0x0
Guest0x0 / HAMT.ml
Created August 7, 2023 17:30
Hash Array Mapped Trie implementation & benchmark in OCaml
(* HAMT v.s. AVL benchmark.
test for their usage as string map.
usage:
> ocamlopt HAMT.ml -o <executable-name>
> <executable-name> (avl|hamt) (random|ordered) <key-length>
time data of the form:
<tree-size> <add-time> <find-time>
@Guest0x0
Guest0x0 / refocusing.ml
Last active December 28, 2024 12:53
demonstration of the refocusing technique for transforming small step reduction to big step interpreter, based on <https://arxiv.org/pdf/2302.10455>
type op = Add | Sub
type expr =
| Lit of int
| Op of expr * op * expr
type result =
| Val of int
| Term of expr
| Stuck
@Guest0x0
Guest0x0 / refocus_generic.ml
Created January 7, 2025 17:35
a generic formalization & evaluation of the "refocus" technique, connecting small-step and big-step evaluators
module type Reduction_Theory = sig
type term
type value
type redex
val v2t : value -> term
val contract : redex -> term option
(* an elementary context is a single frame of elemetary context,
@Guest0x0
Guest0x0 / refocus_direct.ml
Last active January 13, 2025 11:43
transform small-step normalizer in direct style to big-step directly
type op = Add | Sub
type expr =
| Lit of int
| Op of expr * op * expr
type result =
| Val of int
| Term of expr
@Guest0x0
Guest0x0 / STLC-infer-type-graph.ml
Created January 14, 2025 11:37
STLC type inference with type graph optimization via an explicit substitution
type type_name = string
type var = string
type term =
| Atom of { type_name : type_name }
| Var of var
| Lam of var * term
| App of term * term