-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAbstractRepr.sml
107 lines (106 loc) · 3.49 KB
/
AbstractRepr.sml
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
signature Repr =
sig
type repr
type exp
type infixop
type bind
type pat
type atype
type str
type reprrepr
val rep_exp : exp -> repr
val rep_infixop : infixop -> repr
val rep_bind : bind -> repr
val rep_pat : pat -> repr
val rep_atype : atype -> repr
val rep_str : str -> repr
val rep_reprrepr : reprrepr -> repr
val prt_repr : (exp -> 'a) ->
(infixop -> 'a) ->
(bind -> 'a) ->
(pat -> 'a) ->
(atype -> 'a) ->
(str -> 'a) ->
(reprrepr -> 'a) ->
repr -> 'a
val deconstruct_repr :
('a -> 'b) -> ('c -> 'd) -> ('e -> 'f) -> ('g -> 'h) -> ('i -> 'j) ->
('k -> 'l) -> ('m -> 'n) ->
(('a -> string * string * 'b list) -> ('c -> string * string * 'd list) ->
('e -> string * string * 'f list) -> ('g -> string * string * 'h list) ->
('i -> string * string * 'j list) -> ('k -> string * string * 'l list) ->
('m -> string * string * 'n list) -> 'o) -> 'o
val construct_repr :
('a -> exp) -> ('a -> infixop) ->
('a -> bind) -> ('a -> pat) -> ('a -> atype) -> ('a -> str) ->
('a -> reprrepr) -> (repr -> 'b) -> string * 'a list -> 'b
end
functor AbstractRepr
(type repr
type exp
type infixop
type bind
type pat
type atype
eqtype str
type reprrepr
val rep_exp : exp -> repr
val rep_infixop : infixop -> repr
val rep_bind : bind -> repr
val rep_pat : pat -> repr
val rep_atype : atype -> repr
val rep_str : str -> repr
val rep_reprrepr : reprrepr -> repr
val prt_repr : (exp -> 'a) ->
(infixop -> 'a) ->
(bind -> 'a) ->
(pat -> 'a) ->
(atype -> 'a) ->
(str -> 'a) ->
(reprrepr -> 'a) ->
repr -> 'a
) :> Repr
where type exp = exp
and type infixop = infixop
and type bind = bind
and type pat = pat
and type atype = atype
and type str = str
and type repr = repr
and type reprrepr = reprrepr =
struct
type exp = exp
type infixop = infixop
type bind = bind
type pat = pat
type atype = atype
type str = str
type repr = repr
type reprrepr = reprrepr
val rep_exp = rep_exp
val rep_infixop = rep_infixop
val rep_bind = rep_bind
val rep_pat = rep_pat
val rep_atype = rep_atype
val rep_str = rep_str
val rep_reprrepr = rep_reprrepr
val prt_repr = prt_repr
fun deconstruct_repr exp infixop bind pat atype str reprrepr =
fn f => f (fn e => ("repr","exp", [exp e]))
(fn i => ("repr","infixop", [infixop i]))
(fn b => ("repr","bind", [bind b]))
(fn p => ("repr","pat", [pat p]))
(fn t => ("repr","atype", [atype t]))
(fn s => ("repr","str", [str s]))
(fn r => ("repr","reprrepr",[reprrepr r]))
fun construct_repr exp infixop bind pat atype str reprrepr rep_repr =
fn arg => rep_repr
(case arg of ("exp",[e]) => rep_exp (exp e)
| ("infixop",[i]) => rep_infixop (infixop i)
| ("bind",[b]) => rep_bind (bind b)
| ("pat",[p]) => rep_pat (pat p)
| ("atype",[t]) => rep_atype (atype t)
| ("str",[s]) => rep_str (str s)
| ("reprrepr",[r]) => rep_reprrepr (reprrepr r)
| (c,l) => raise Fail "repr: no case")
end