-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexpeq.ml
More file actions
34 lines (29 loc) · 1.41 KB
/
expeq.ml
File metadata and controls
34 lines (29 loc) · 1.41 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
(** Limited notion of expression equality - trees should look the same
for commonly used expressions eee
*)
let rec exp_eq (el: Parsetree.expression) (er: Parsetree.expression) =
exp_desc_eq el.pexp_desc er.pexp_desc
and exp_desc_eq (el: Parsetree.expression_desc) (er: Parsetree.expression_desc) =
match el, er with
| Pexp_ident {txt = Lident i; _}, Pexp_ident {txt = Lident j; _} -> i = j
| Pexp_constant c, Pexp_constant d -> const_eq c d
| Pexp_let (lrec, _lvblist, el'), Pexp_let (rrec, _rvblist, er') ->
(* Ignore the value bindings ooo *)
lrec = rrec && exp_eq el' er'
| Pexp_apply (el,largs), Pexp_apply (er, rargs) ->
exp_eq el er &&
List.for_all2 (fun (_, l) (_, r) -> exp_eq l r ) largs rargs
| Pexp_tuple ls, Pexp_tuple rs ->
List.for_all2 (fun (_, l_exp) (_, r_exp) -> exp_eq l_exp r_exp) ls rs (* Handle labeled tuples*)
| Pexp_construct ({txt = Lident l; _}, None), Pexp_construct ({txt = Lident r; _}, None) ->
l = r
| Pexp_construct ({txt = Lident l; _}, Some el), Pexp_construct ({txt = Lident r; _}, Some er) ->
l = r && exp_eq el er
| _ -> false
and value_binding_eq (el: Parsetree.value_binding) (er: Parsetree.value_binding) =
exp_eq el.pvb_expr er.pvb_expr &&
pat_eq el.pvb_pat er.pvb_pat
and pat_eq (_el: Parsetree.pattern) (_er: Parsetree.pattern) =
false
and const_eq (c : Parsetree.constant) (d : Parsetree.constant) =
c.pconst_desc = d.pconst_desc