Coder Social home page Coder Social logo

tt's Introduction

A minimalist implementation of type theory in Ocaml. The repository holds several branches which correspond to a series of blog posts about dependent type theory on the Mathematics and Computation blog.

The type theory

The dependent type theory tt has the following ingridients:

  • The universes are Type 0, Type 1, Type 2, ...
  • A dependent product is written as forall x : T1, T2
  • A function is written as fun x : T => e
  • Application is written as e1 e2

The hierarchy of universes is not commulative, i.e., even though Type k has type Type (k+1), Type k is not a subuniverse of Type (k+1).

Compilation

You need ocamlbuild, which is part of OCaml, the menhir parser generator, and make. You can type

  • make to make the tt.native executable.
  • make byte to make the bytecode tt.byte executable.
  • make clean to clean up.
  • make doc to generate HTML documentation (see the generated tt.docdir/index.html).

Usage

Type Help. in the interactive shell to see what the type system can do. Here is a sample session:

tt blog-part-I
[Type Ctrl-D to exit or "Help." for help.]
# Parameter N : Type 0.
N is assumed
# Parameter z : N. Parameter s : N -> N.
z is assumed
s is assumed
# Definition three := fun f : N -> N => fun x : N => f (f (f x)).
three is defined
# Context.
three = fun f : N -> N => fun x : N => f (f (f x))
    : (N -> N) -> N -> N
s : N -> N
z : N
N : Type 0
# Check (three (three s)).
three (three s)
    : N -> N
# Eval (three (three s)) z.
    = s (s (s (s (s (s (s (s (s z))))))))
    : N

Source code

The purpose of the implementation is to keep the source uncomplicated and short. The essential bits of source code can be found in the following files. It should be possible for you to just read the entire source code. You should start with the core

  • syntax.ml -- abstract syntax
  • context.ml -- contexts
  • norm.ml -- normalization
  • typing.ml -- type inference and normalization

and continue with the infrastructure

  • tt.ml -- interactive top level
  • error.ml -- error reporting
  • desugar.ml -- convert names to de Bruijn indices
  • lexer.mll and parser.mly -- concrete sytnax
  • beautify.ml and print.ml -- pretty printing

Inefficiency

The code is meant to be short and sweet, and close to how type theory is presented on paper. Therefore, it is not suitable for a real implementation, as it will get horribly inefficient as soon as you try anything complicated. But it should be useful for experimentation.

What experiments should I perform to learn more?

There are many things you can try, for example:

  • basic types unit, bool and nat
  • the eta rule for functions
  • dependent sums
  • cummulative universes, so that [A : Type k] implies [A : Type (k+1)]
  • better type inference so that variables need not be explicitly typed
  • prefix and infix operators

tt's People

Contributors

andrejbauer avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.