bobatkey/sott
{ "createdAt": "2017-09-06T12:51:30Z", "defaultBranch": "master", "description": "Simplified Observational Type Theory", "fullName": "bobatkey/sott", "homepage": null, "language": "OCaml", "name": "sott", "pushedAt": "2023-05-05T15:57:48Z", "stargazersCount": 86, "topics": [], "updatedAt": "2025-11-17T06:29:46Z", "url": "https://github.com/bobatkey/sott"}Simplified Observational Type Theory
Section titled “Simplified Observational Type Theory”This is an implementation of Observational Type Theory. It is “simplified” because the definitions of equality of types and terms do not reduce as in the original definition. Instead, the theory provides ways to construct proofs of equality, and to project out consequences of an equality (e.g., equal pairs implies the components are equal). Not reducing equality propositions stops (this source of) explosion of the sizes of types.
How to build it
Section titled “How to build it”- Make sure you have opam installed.
- Install dependencies locally
opam switch create . --deps-only - Update shell environment:
eval $(opam env) dune build
How to typecheck a file
Section titled “How to typecheck a file”dune exec cmd/sott.exe typecheck <file.sott>
Examples
Section titled “Examples”-
[test1.sott]!(test1.sott) Derivation of
transportfromcoerce; and a demonstration that Hofmann’s counterexample to canonicity in the presence of a functional extensionality axiom fails in OTT. -
[test1.5.sott]!(test1.5.sott) Shortened version of [test1.sott]!(test1.sott).
-
[test2.sott]!(test2.sott) An equality-proof irrelevance test; transivity and symmetry; coherence.
-
[test3.sott]!(test3.sott) Encoding of sum types via booleans and sigma types; demonstration that the counterexample to canonicity involving constructors when adding functional extensionality fails in OTT [https://coq.inria.fr/cocorico/extensional_equality].
-
[arith.sott]!(arith.sott) Construction of and some proofs for the integers constructed as a quotient of pairs of natural numbers.
Features
Section titled “Features”-
Type equalities, written
[A = B], whereAandBare proper types. All proofs of the same equality are definitionally equal. -
Heterogeneous term equality, written
[a : A = b : B], whereAandBare types. As a shorthand, ifAis the same asB, then this can be written as[a = b : A]. All proofs of the same equality are definitionally equal. -
Reflexivity for both type and term equality, written
refl. -
Coercion, written as
coerce(a,A,B,p), whereAandBare types,a : A, andp : [A = B]. IfAandBare in normal form, then the coercion will compute as appropriate to the type. This is how we maintain canonicity even when the equality type is arbitrarily extended. -
Coherence,
coherence(e)wheree : [A = B], has type[x : A = coerce(x,A,B,e) : B](thexis inferred from the type being pushed in). -
Pi types:
(x : A) -> B,\x -> eande1 e2. Function extensionality is witnessed byfunext(x1 x2 x_e. XXX) : [f1 : (x : A1) -> B1 = f2 : (x : A2) -> B2], wherex1 : A1,x2 : A2,x_e : [x1 : A1 = x2 : A2]andXXX : [f1 x1 : B1[x1] = f2 x2 : B2[x2]]. -
Sigma types
(x : A) * B,(x,y)andx #fst,x #snd. -
Booleans:
Bool,True,Falseandx for x. T { True -> e1; False -> e2 }. -
Natural numbers:
Nat,Zero,Succ nandx for y. T { Zero -> e1; Succ n p -> e2 }. -
A Russell-style universe
Set, which includes equalities, booleans, naturals, Pi, Sigma. -
Quotient types:
-
Formation:
A / R, whereAis a type andR : A -> A -> Set -
Introduction:
[a] : A / R, wherea : A -
Elimination:
x for z. T { [z] -> e1; z1 z2 zr -> e2 }. The expressione1computes the answer, ande2is a proof thate1doesn’t depend on the equivalence class. -
Propositional equality:
same-class(e) : [[a1] : A/R = [a2] : A/R]whene : R a1 a2.
-
Bugs/TODO
Section titled “Bugs/TODO”-
The parser reports a line number on error, but otherwise the error messages are useless. One day, I hope to use Menhir’s fancy error message support.
-
Not every useful combinator for equalities is present. This is a matter of implementing them in the lexer/parser/typechecker.
-
The normaliser is a bit too keen and unfolds all definitions whether it needs to for equality checking or not. This leads to massive terms during type checking. Error messages are now reported without unfolded definitions though, which makes them a bit easier to read.
-
Type error messages don’t include the context, and may output names that shadow names in the context, leading to incorrect terms.