Skip to content

Commit

Permalink
Better readme and other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejbauer committed Nov 7, 2012
1 parent 4c34b3b commit bb868ec
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@ _build
tt.native tt.native
tt.byte tt.byte
parser.conflicts parser.conflicts
tt.docdir


# Backup files # Backup files
*~ *~
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -3,3 +3,6 @@ all:


clean: clean:
ocamlbuild -clean ocamlbuild -clean

doc:
ocamlbuild -use-menhir -docflag -keep-code -lib unix tt.docdir/index.html
41 changes: 28 additions & 13 deletions README.markdown
@@ -1,11 +1,19 @@
A minimalist implementation of type theory with universes indexed by numerals and A minimalist implementation of type theory with universes and dependent products. The
dependent products. The concrete syntax is as follows: concrete syntax is as follows:


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


## Compilation

You need `ocamlbuild` and `make`. You can type

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

## Usage ## Usage


Type `Help.` in the interactive shell to see what the type system can do. Here is a sample Type `Help.` in the interactive shell to see what the type system can do. Here is a sample
Expand All @@ -31,17 +39,24 @@ session:
## Source code ## Source code


The purpose of the implementation is to keep the source uncomplicated and short. The 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: 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
* `ctx.ml` -- contexts
* `infer.ml` -- type inference and normalization

and continue with the infrastructure

* `tt.ml` -- interactive top level
* `error.ml` -- error reporting
* `lexer.mll` and `parser.mly` -- concrete sytnax
* `beautify.ml` and `print.ml` -- pretty printing


* `concrete.ml` the abstract syntax
* `syntax.ml` compiled form of abstract syntax, where abstractions are Ocaml functions, normalization
* `infer.ml` type checking


The rest of the files are just logistics: ## Inefficiency


* `lexer.mll` lexical analysis of concrete syntax The code is meant to be short and sweet, and close to how type theory is presented on
* `parser.mly` parser which converts concrete syntax to abstract syntax paper. Therefore, it is not suitable for a real implementation, as it will get horribly
* `print.ml` pretty-printing of expressions inefficient as soon as you try anything complicated. But it should be useful for
* `common.ml` commonly used functions experimentation.
* `error.ml` printing of errors
* `tt.ml` toplevel interactive shell
20 changes: 12 additions & 8 deletions ctx.ml
@@ -1,17 +1,21 @@
(* Contexts *) (** Handling of contexts.
let lookup = List.assoc
A context is represented as an associative list which maps a variable [x]
to a pair [(t,e)] where [t] is its type and [e] is its value (optional).
*)


let index x ctx = let lookup = List.assoc
let rec index k = function
| [] -> raise Not_found
| y :: ys -> if x = y then k else index (k+1) ys
in
index 0 ctx


(** [lookup_ty x ctx] returns the type of [x] in context [ctx]. *)
let lookup_ty x ctx = fst (lookup x ctx) let lookup_ty x ctx = fst (lookup x ctx)


(** [lookup_ty x ctx] returns the value of [x] in context [ctx], or [None]
if [x] has no assigned value. *)
let lookup_value x ctx = snd (lookup x ctx) let lookup_value x ctx = snd (lookup x ctx)


(** [extend x t ctx] returns [ctx] extended with variable [x] of type [t],
whereas [extend x t ~value:e ctx] returns [ctx] extended with variable [x]
of type [t] and assigned value [e]. *)
let extend x t ?value ctx = (x, (t, value)) :: ctx let extend x t ?value ctx = (x, (t, value)) :: ctx




2 changes: 2 additions & 0 deletions lexer.mll
@@ -1,4 +1,6 @@
{ {
(** The lexer. *)

open Parser open Parser


let reserved = [ let reserved = [
Expand Down
2 changes: 2 additions & 0 deletions syntax.ml
@@ -1,3 +1,4 @@
(** Abstract syntax of expressions and toplevel directives. *)


(** During substitution we generate fresh variable names. Because we want pretty printing, (** During substitution we generate fresh variable names. Because we want pretty printing,
each freshly generated variable name should "remember" its preferred form. Thus a each freshly generated variable name should "remember" its preferred form. Thus a
Expand All @@ -21,6 +22,7 @@ type expr =
| Lambda of abstraction | Lambda of abstraction
| App of expr * expr | App of expr * expr


(** An abstraction [(x,t,e)] indicates that [x] of type [t] is bound in [e]. *)
and abstraction = variable * expr * expr and abstraction = variable * expr * expr


(** Toplevel directives. *) (** Toplevel directives. *)
Expand Down
9 changes: 9 additions & 0 deletions tt.odocl
@@ -0,0 +1,9 @@
Syntax
Error
Ctx
Infer
Tt
Beautify
Print


0 comments on commit bb868ec

Please sign in to comment.