-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmml.ml
More file actions
75 lines (65 loc) · 1.32 KB
/
mml.ml
File metadata and controls
75 lines (65 loc) · 1.32 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
(* Abstract Syntax for Mini-ML *)
type typ =
| TInt
| TBool
| TUnit
| TFun of typ * typ
| TStrct of string
| TMatch
| TAnything
| TArray of typ
type strct = (string * typ * bool) list
type uop =
| Neg
| Not
type bop =
| Add
| Sub
| Mul
| Div
| Mod
| Eq
| Neq
| Lt
| Le
| And
| Or
type luop =
| Len
type lbop =
| Concat
| EqL
type expr =
| Int of int
| Bool of bool
| Unit
| Uop of uop * expr
| Bop of bop * expr * expr
| Var of string
| Let of string * expr * expr
| If of expr * expr * expr
| Fun of string * typ * expr
| App of expr * expr
| Fix of string * typ * expr
| Strct of (string * expr) list
| GetF of expr * string
| SetF of expr * string * expr
| Seq of expr * expr
(* extensions *)
| Array of string * typ * (expr) list
| ListUop of luop * expr
| ListBop of lbop * expr * expr
| MatchPattern of expr * (expr) list
| MatchPossibility of expr * expr
| Anything
type prog = {
types: (string * strct) list;
code: expr;
}
(* Usable functions to handle functions with multiple arguments *)
let rec mk_fun xs e = match xs with
| [] -> e
| (x, t)::xs -> Fun(x, t, mk_fun xs e)
let rec mk_fun_type xs t = match xs with
| [] -> t
| (_, t')::xs -> TFun(t', mk_fun_type xs t)