-
Notifications
You must be signed in to change notification settings - Fork 18
/
syntax.ml
53 lines (47 loc) · 1.12 KB
/
syntax.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
open Util
type tm = tm' Location.t
and tm' =
| Var of string
| Let of string * tm * tm
| Type
| Prod of (string * ty) * ty
| Lambda of (string * ty option) * tm
| Apply of tm * tm
| Ascribe of tm * ty
(* Parsed type (equal to tmession). *)
and ty = tm
(* Parsed top-level command. *)
type toplevel = toplevel' Location.t
and toplevel' =
| TopLoad of string
| TopDefinition of string * tm
| TopCheck of tm
| TopEval of tm
| TopAxiom of string * ty
let prod xus t =
let rec fold = function
| [] -> t
| Location.{loc; data=(xs, u)} :: xus ->
let rec fold' = function
| [] -> fold xus
| x :: xs ->
Location.locate ~loc (Prod ((x, u), fold' xs))
in
fold' xs
in
(fold xus).Location.data
let lambda xus t =
let rec fold = function
| [] -> t
| Location.{loc; data=(xs, uopt)} :: xus ->
let rec fold' = function
| [] -> fold xus
| x :: xs ->
Location.locate ~loc (Lambda ((x, uopt), fold' xs))
in
fold' xs
in
(fold xus).Location.data
let arrow u t =
let x = Name.anonymous () in
Prod ((x, u), t)