Skip to content

Instantly share code, notes, and snippets.

View brendanzab's full-sized avatar
πŸ˜΅β€πŸ’«
writing elaborators

Brendan Zabarauskas brendanzab

πŸ˜΅β€πŸ’«
writing elaborators
View GitHub Profile
@brendanzab
brendanzab / set.pol
Last active March 25, 2025 11:43
Set interface as a codata type in Polarity (see: https://polarity-lang.github.io)
data Bool { T, F }
data Nat { Z, S(n: Nat) }
def (n1: Nat).eq(n2: Nat): Bool {
Z => n2.match {
Z => T,
S(_) => F,
},
S(n1) => n2.match {
@brendanzab
brendanzab / intuitionistic.elf
Last active March 17, 2025 11:49
Intuitionistic type theory in Twelf (try in the playground at: https://twelf.org/twelf-wasm/)
%% Intuitionistic type theory in Twelf by Brendan Zabarauskas
%%
%% Inspired by the examples found in β€œAn Equational Logical Framework
%% for Type Theories” https://arxiv.org/abs/2106.01484
tp : type.
el : tp -> type.
%% Equality
module type Isorecursive = sig
type t
type 'a layer
val roll : t layer -> t
val unroll : t -> t layer
end
module Option = struct
type 'a shape = [
| `Some of 'a
| `None
]
module type S = sig
type 'a t
@brendanzab
brendanzab / ast_folds.ml
Created February 25, 2025 11:30
Folding over an AST using recursion schemes (a response to https://bsky.app/profile/bandukwala.me/post/3liwrjfotek2a).
module Expr = struct
module Layer = struct
type 'a t =
| Mul of 'a * 'a
| Add of 'a * 'a
| Int of int
let map (f : 'a -> 'b) (layer : 'a t) : 'b t =
@brendanzab
brendanzab / eval_stmts_cps.ml
Last active February 11, 2025 03:46
An evaluator for an imperative language with loop, break, and continue in continuation passing style.
(** An evaluator for an imperative language with loop, break, and continue in
continuation passing style. *)
type expr =
| Var of string
| Let of string * expr * expr
| Seq of expr * expr
| Unit
@brendanzab
brendanzab / lambda_nbe.ml
Last active February 4, 2025 03:17
Evaluator for a lambda calculus with de Bruijn indices, levels, and defunctionalised closures. For more, check out the language garden: https://github.com/brendanzab/language-garden/
type index = int
type level = int
type expr =
| Var of index
| Let of string * expr * expr
| Fun_lit of string * expr
| Fun_app of expr * expr
@brendanzab
brendanzab / set_objects.ml
Last active November 18, 2024 13:56
Set examples in OCaml based on William R. Cook’s β€œOn Understanding Data Abstraction, Revisited”
(** Set examples in OCaml from {{:https://www.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf}
β€œOn Understanding Data Abstraction, Revisited”} by William R. Cook
*)
(** ADT-style set implementations.
See Section 2 of the paper.
*)
module Abstract_data_types = struct

What is a type” in the semantic domain called?

One frustration I’ve run into when making a type checker/elaborator for a programming language is the following gap in terminology:

  • term1 / value
  • type / ???

This most commonly pops up when using normalisation-by-evaluation as part of a type checker, for example in the elab-system-f-bidirectional or elab-dependent projects in my language garden:

Footnotes

  1. Or an β€œexpression” ↩

@brendanzab
brendanzab / bank-account.pol
Last active September 26, 2024 10:38
Bank account interface as a codata type in Polarity (see: https://polarity-lang.github.io)
-- UML Class diagram:
--
-- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
-- β”‚ BankAccount |
-- β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
-- β”‚ - owner : String |
-- β”‚ - balance : Dollars = 0 |
-- β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
-- β”‚ + getOwner() : String |
-- β”‚ + getBalance() : Dollars |