|
1 | 1 | (* Henk: CoC 1988 with infinite hierarchy of predicative universes *) |
2 | 2 |
|
3 | 3 | type term = |
4 | | - | Var of string |
5 | | - | Universe of int |
6 | | - | Pi of string * term * term (* ∀ (x : a), b *) |
7 | | - | Lam of string * term * term (* λ (x : a), b *) |
8 | | - | App of term * term |
| 4 | + | Var of string |
| 5 | + | Universe of int |
| 6 | + | Pi of string * term * term (* ∀ (x : a), b *) |
| 7 | + | Lam of string * term * term (* λ (x : a), b *) |
| 8 | + | App of term * term |
9 | 9 |
|
10 | | -type context = (string * term) list |
| 10 | +let rec string_of_term = function |
| 11 | + | Var x -> x |
| 12 | + | Universe u -> "U_" ^ string_of_int u |
| 13 | + | Pi (x, a, b) -> "∀ (" ^ x ^ " : " ^ string_of_term a ^ "), " ^ string_of_term b |
| 14 | + | Lam (x, a, t) -> "λ (" ^ x ^ " : " ^ string_of_term a ^ "), " ^ string_of_term t |
| 15 | + | App (t1, t2) -> "(" ^ string_of_term t1 ^ " " ^ string_of_term t2 ^ ")" |
11 | 16 |
|
| 17 | +type context = (string * term) list |
12 | 18 | exception TypeError of string |
13 | 19 |
|
| 20 | +let universe = function |
| 21 | + | Universe i -> if i < 0 then raise (TypeError "Negative universe level"); i |
| 22 | + | ty -> raise (TypeError (Printf.sprintf "Expected a universe, got: %s" (string_of_term ty))) |
| 23 | + |
14 | 24 | let rec subst x s = function |
15 | 25 | | Var y -> if x = y then s else Var y |
16 | 26 | | Pi (y, a, b) when x <> y -> Pi (y, subst x s a, subst x s b) |
@@ -53,18 +63,6 @@ and infer ctx t = |
53 | 63 | | App (f, arg) -> match infer ctx f with | Pi (x, a, b) -> subst x arg b | ty -> raise (TypeError "Application requires a Pi type.") |
54 | 64 | in normalize ctx res |
55 | 65 |
|
56 | | -let universe ty = |
57 | | - match ty with |
58 | | - | Universe i -> if i < 0 then raise (TypeError "Negative universe level"); i |
59 | | - | ty -> raise (TypeError (Printf.sprintf "Expected a universe, got: %s" (string_of_term ty))) |
60 | | - |
61 | | -let rec string_of_term = function |
62 | | - | Var x -> x |
63 | | - | Universe u -> "U_" ^ string_of_int u |
64 | | - | Pi (x, a, b) -> "∀ (" ^ x ^ " : " ^ string_of_term a ^ "), " ^ string_of_term b |
65 | | - | Lam (x, a, t) -> "λ (" ^ x ^ " : " ^ string_of_term a ^ "), " ^ string_of_term t |
66 | | - | App (t1, t2) -> "(" ^ string_of_term t1 ^ " " ^ string_of_term t2 ^ ")" |
67 | | - |
68 | 66 | (* Test Suite *) |
69 | 67 |
|
70 | 68 | let nat_type = |
|
0 commit comments