-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ml
35 lines (31 loc) · 1.08 KB
/
types.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
type t =
| Never
| Int
| Bool
| Str
| Fun of t * t
| Tuple of t list
| Poly of int
| Variant of t list * Id.t
let rec show = function
| Never -> "never"
| Int -> "int"
| Bool -> "bool"
| Str -> "string"
| Fun (Fun _ as arg, ret) -> Printf.sprintf "(%s) -> %s" (show arg) (show ret)
| Fun (arg, ret) -> Printf.sprintf "%s -> %s" (show arg) (show ret)
| Tuple ts -> begin match List.map (
function
| (Fun _ | Tuple _) as t -> Printf.sprintf "(%s)" @@ show t
| t -> show t
) ts with
| [] -> "unit"
| head :: tail -> List.fold_left (fun acc t -> acc ^ " * " ^ t) head tail
end
| Poly id -> Printf.sprintf "'%d" id
| Variant ([], id) -> Id.show id
| Variant ([arg], id) -> Printf.sprintf "%s %s" (show arg) (Id.show id)
| Variant (arg_head :: arg_tail, id) -> Printf.sprintf "(%s) %s" (List.fold_left (fun acc t -> acc ^ ", " ^ show t) (show arg_head) arg_tail) (Id.show id)
let pp fmt t = Format.fprintf fmt "%s" (show t)
let unit = Tuple []
type scheme_t = int * t