Skip to content

Instantly share code, notes, and snippets.

@zehnpaard
zehnpaard / inf2.ml
Last active October 27, 2022 03:07
Monomorphic Type Inference with Mutable Type Variable Generation and Unification from TaPL, https://github.com/hsk/simpletapl and https://github.com/tomprimozic/type-systems
type ty =
| TVar of tvar ref
| TArrow of ty * ty
and tvar =
| Unbound of int
| Link of ty
type exp =
| EVar of string
| EAbs of string * exp
@zehnpaard
zehnpaard / inf1.ml
Last active October 23, 2022 15:08
Monomorphic Type Inference with Mutable Type Variable Generation from Types and Programming Languages, simplified based on https://github.com/hsk/simpletapl
type ty =
| TVar of int
| TArrow of ty * ty
type exp =
| EVar of string
| EAbs of string * exp
| EApp of exp * exp
let new_tvar =
@zehnpaard
zehnpaard / inf0.ml
Last active October 23, 2022 15:09
Purely Functional Monomorphic Type Inference from Types and Programming Languages, simplified based on https://github.com/hsk/simpletapl
type ty =
| TVar of int
| TArrow of ty * ty
type exp =
| EVar of string
| EAbs of string * exp
| EApp of exp * exp
type new_tvar = NewTVar of ty * (unit -> new_tvar)
@zehnpaard
zehnpaard / sb8bad.ml
Created October 9, 2022 17:57
Incomplete Simple Bool with Nat, Let, Records, Variants, Fix, Ref, Error from Types and Programming Languages, simplified based on https://github.com/hsk/simpletapl
type ty =
| TArrow of ty * ty
| TBool
| TNat
| TRecord of (string * ty) list
| TVariant of (string * ty) list
| TUnit
| TRef of ty
| TBottom
@zehnpaard
zehnpaard / sb8.ml
Last active October 18, 2022 02:19
Simple Bool with Nat, Let, Records, Variants, Fix, Ref, Error from Types and Programming Languages, simplified based on https://github.com/hsk/simpletapl
type ty =
| TArrow of ty * ty
| TBool
| TNat
| TRecord of (string * ty) list
| TVariant of (string * ty) list
| TUnit
| TRef of ty
| TBottom
@zehnpaard
zehnpaard / sb7.ml
Last active October 8, 2022 21:24
Simple Bool with Nat, Let, Records, Variants, Fix, Ref from Types and Programming Languages, simplified based on https://github.com/hsk/simpletapl
type ty =
| TArrow of ty * ty
| TBool
| TNat
| TRecord of (string * ty) list
| TVariant of (string * ty) list
| TUnit
| TRef of ty
type exp =
@zehnpaard
zehnpaard / sb6.ml
Last active October 8, 2022 21:24
Simple Bool with Nat, Let, Records, Variants, Fix from Types and Programming Languages, simplified based on https://github.com/hsk/simpletapl
type ty =
| TArrow of ty * ty
| TBool
| TNat
| TRecord of (string * ty) list
| TVariant of (string * ty) list
type exp =
| EVar of string
| EAbs of string * ty * exp
@zehnpaard
zehnpaard / sb5.ml
Last active October 8, 2022 20:48
Simple Bool with Nat, Let, Records, Variants from Types and Programming Languages, simplified based on https://github.com/hsk/simpletapl
type ty =
| TArrow of ty * ty
| TBool
| TNat
| TRecord of (string * ty) list
| TVariant of (string * ty) list
type exp =
| EVar of string
| EAbs of string * ty * exp
@zehnpaard
zehnpaard / sb0.ml
Created October 3, 2022 02:12
STLC from Types and Programming Languages, simplified based on https://github.com/hsk/simpletapl
type ty =
| TArrow of ty * ty
type exp =
| EVar of string
| EAbs of string * ty * exp
| EApp of exp * exp
let rec typeof env = function
| EVar var -> List.assoc var env
@zehnpaard
zehnpaard / sb4.ml
Last active October 4, 2022 02:37
Simple Bool with Nat, Let, Records from Types and Programming Languages, simplified based on https://github.com/hsk/simpletapl
type ty =
| TArrow of ty * ty
| TBool
| TNat
| TRecord of (string * ty) list
type exp =
| EVar of string
| EAbs of string * ty * exp
| EApp of exp * exp