| 7 |
type capture = string |
type capture = string |
| 8 |
type fv = capture SortedList.t |
type fv = capture SortedList.t |
| 9 |
|
|
| 10 |
exception IllFormedCup of fv * fv |
exception Error of string |
| 11 |
exception IllFormedCap of fv * fv |
|
| 12 |
|
|
| 13 |
(* Syntactic algebra *) |
(* Syntactic algebra *) |
| 14 |
|
|
| 40 |
|
|
| 41 |
let constr x = (Types.descr x,[],Constr x) |
let constr x = (Types.descr x,[],Constr x) |
| 42 |
let cup ((acc1,fv1,_) as x1) ((acc2,fv2,_) as x2) = |
let cup ((acc1,fv1,_) as x1) ((acc2,fv2,_) as x2) = |
| 43 |
if fv1 <> fv2 then raise (IllFormedCup (fv1,fv2)); |
if fv1 <> fv2 then ( |
| 44 |
|
let x = match SortedList.diff fv1 fv2 with |
| 45 |
|
| x::_ -> x |
| 46 |
|
| [] -> match SortedList.diff fv2 fv1 with x::_ -> x | _ -> assert false |
| 47 |
|
in |
| 48 |
|
raise |
| 49 |
|
(Error |
| 50 |
|
("The capture variable " ^ x ^ |
| 51 |
|
" should appear on both side of this | pattern")) |
| 52 |
|
); |
| 53 |
(Types.cup acc1 acc2, SortedList.cup fv1 fv2, Cup (x1,x2)) |
(Types.cup acc1 acc2, SortedList.cup fv1 fv2, Cup (x1,x2)) |
| 54 |
let cap ((acc1,fv1,_) as x1) ((acc2,fv2,_) as x2) e = |
let cap ((acc1,fv1,_) as x1) ((acc2,fv2,_) as x2) e = |
| 55 |
if not (SortedList.disjoint fv1 fv2) then raise (IllFormedCap (fv1,fv2)); |
if not (SortedList.disjoint fv1 fv2) then ( |
| 56 |
|
match SortedList.cap fv1 fv2 with |
| 57 |
|
| x::_ -> |
| 58 |
|
raise |
| 59 |
|
(Error |
| 60 |
|
("The capture variable " ^ x ^ |
| 61 |
|
" cannot appear on both side of this & pattern")) |
| 62 |
|
| _ -> assert false |
| 63 |
|
); |
| 64 |
(Types.cap acc1 acc2, SortedList.cup fv1 fv2, Cap (x1,x2,e)) |
(Types.cap acc1 acc2, SortedList.cup fv1 fv2, Cap (x1,x2,e)) |
| 65 |
let times x y = |
let times x y = |
| 66 |
(Types.times x.accept y.accept, SortedList.cup x.fv y.fv, Times (x,y)) |
(Types.times x.accept y.accept, SortedList.cup x.fv y.fv, Times (x,y)) |