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
|
(* The the code found in add_builtin. *)
let () =
(* x.l1.l2.l3 = v means
x = (x where l1 = (x.l1 where l2 = (x.l1.l2 where l3 = v)))
*)
let x = "x" in
let v = "v" in
let rec aux prefix = function
| l :: ll ->
Printf.sprintf "%s%s%s where (%s = %s)" x
(if prefix = [] then "" else ".")
(String.concat "." (List.rev prefix))
l
(aux (l :: prefix) ll)
| [] -> v
in
let ll = ["l1"; "l2"; "l3"] in
Printf.printf "%s = %s\n\n%!" x (aux [] ll)
(* Test adding submethods. *)
let () =
let print t = Printf.printf "%s\n%!" (Type.to_string t) in
let t = Type.make Type.Int in
print t;
let t = Type.meth "f" ([], Type.make Type.Float) t in
print t;
let t = Type.meth "ff" ([], Type.make Type.Float) t in
print t;
let t = Type.meths ["f"; "s"] ([], Type.make Type.String) t in
print t;
let t = Type.meths ["f"; "s"; "f'"] ([], Type.make Type.Float) t in
print t
(* Test subtyping. *)
let () =
(* Make sure unifying variables sees top-level methods:
We do: t = ('a).{ f : int } <: t' = int.{ ff : int, f : float }
and make sure that this fails. *)
let t = Type.var () in
let t = Type.meth "f" ([], Type.make Type.Int) t in
let t' = Type.make Type.Int in
let t' = Type.meth "f" ([], Type.make Type.Float) t' in
let t' = Type.meth "ff" ([], Type.make Type.Int) t' in
assert (
try
Typing.(t <: t');
false
with _ -> true)
|