2011-11-24 01:02:48 -08:00
|
|
|
|
|
|
|
# type 'a ty =
|
|
|
|
Int : int ty
|
|
|
|
| String : string ty
|
|
|
|
| List : 'a ty -> 'a list ty
|
|
|
|
| Pair : ('a ty * 'b ty) -> ('a * 'b) ty
|
|
|
|
# type variant =
|
|
|
|
VInt of int
|
|
|
|
| VString of string
|
|
|
|
| VList of variant list
|
|
|
|
| VPair of variant * variant
|
2011-12-27 00:52:45 -08:00
|
|
|
val variantize : 't ty -> 't -> variant = <fun>
|
2011-11-24 01:02:48 -08:00
|
|
|
exception VariantMismatch
|
2011-12-27 00:52:45 -08:00
|
|
|
val devariantize : 't ty -> variant -> 't = <fun>
|
2011-11-24 01:02:48 -08:00
|
|
|
# type 'a ty =
|
|
|
|
Int : int ty
|
|
|
|
| String : string ty
|
|
|
|
| List : 'a ty -> 'a list ty
|
|
|
|
| Pair : ('a ty * 'b ty) -> ('a * 'b) ty
|
|
|
|
| Record : 'a record -> 'a ty
|
|
|
|
and 'a record = { path : string; fields : 'a field_ list; }
|
|
|
|
and 'a field_ = Field : ('a, 'b) field -> 'a field_
|
|
|
|
and ('a, 'b) field = { label : string; field_type : 'b ty; get : 'a -> 'b; }
|
|
|
|
# type variant =
|
|
|
|
VInt of int
|
|
|
|
| VString of string
|
|
|
|
| VList of variant list
|
|
|
|
| VPair of variant * variant
|
|
|
|
| VRecord of (string * variant) list
|
2011-12-27 00:52:45 -08:00
|
|
|
val variantize : 't ty -> 't -> variant = <fun>
|
2011-11-24 01:02:48 -08:00
|
|
|
# type 'a ty =
|
|
|
|
Int : int ty
|
|
|
|
| String : string ty
|
|
|
|
| List : 'a ty -> 'a list ty
|
|
|
|
| Pair : ('a ty * 'b ty) -> ('a * 'b) ty
|
|
|
|
| Record : ('a, 'builder) record -> 'a ty
|
|
|
|
and ('a, 'builder) record = {
|
|
|
|
path : string;
|
|
|
|
fields : ('a, 'builder) field list;
|
|
|
|
create_builder : unit -> 'builder;
|
|
|
|
of_builder : 'builder -> 'a;
|
|
|
|
}
|
|
|
|
and ('a, 'builder) field =
|
|
|
|
Field : ('a, 'builder, 'b) field_ -> ('a, 'builder) field
|
|
|
|
and ('a, 'builder, 'b) field_ = {
|
|
|
|
label : string;
|
|
|
|
field_type : 'b ty;
|
|
|
|
get : 'a -> 'b;
|
|
|
|
set : 'builder -> 'b -> unit;
|
|
|
|
}
|
2011-12-27 00:52:45 -08:00
|
|
|
val devariantize : 't ty -> variant -> 't = <fun>
|
2011-11-24 01:02:48 -08:00
|
|
|
# type my_record = { a : int; b : string list; }
|
|
|
|
val my_record : my_record ty =
|
|
|
|
Record
|
|
|
|
{path = "My_module.my_record";
|
|
|
|
fields =
|
|
|
|
[Field {label = "a"; field_type = Int; get = <fun>; set = <fun>};
|
|
|
|
Field {label = "b"; field_type = List String; get = <fun>; set = <fun>}];
|
|
|
|
create_builder = <fun>; of_builder = <fun>}
|
|
|
|
# type noarg = Noarg
|
2011-12-27 18:22:38 -08:00
|
|
|
type (_, _) ty =
|
2011-11-24 01:02:48 -08:00
|
|
|
Int : (int, 'c) ty
|
|
|
|
| String : (string, 'd) ty
|
|
|
|
| List : ('a, 'e) ty -> ('a list, 'e) ty
|
|
|
|
| Option : ('a, 'e) ty -> ('a option, 'e) ty
|
|
|
|
| Pair : (('a, 'e) ty * ('b, 'e) ty) -> ('a * 'b, 'e) ty
|
|
|
|
| Var : ('a, 'a -> 'e) ty
|
|
|
|
| Rec : ('a, 'a -> 'e) ty -> ('a, 'e) ty
|
|
|
|
| Pop : ('a, 'e) ty -> ('a, 'b -> 'e) ty
|
|
|
|
| Conv : string * ('a -> 'b) * ('b -> 'a) * ('b, 'e) ty -> ('a, 'e) ty
|
|
|
|
| Sum : ('a, 'e, 'b) ty_sum -> ('a, 'e) ty
|
|
|
|
and ('a, 'e, 'b) ty_sum = {
|
|
|
|
sum_proj : 'a -> string * 'e ty_dyn option;
|
|
|
|
sum_cases : (string * ('e, 'b) ty_case) list;
|
|
|
|
sum_inj : 'c. ('b, 'c) ty_sel * 'c -> 'a;
|
|
|
|
}
|
|
|
|
and 'e ty_dyn = Tdyn : ('a, 'e) ty * 'a -> 'e ty_dyn
|
2011-12-27 18:22:38 -08:00
|
|
|
and (_, _) ty_sel =
|
2011-11-24 01:02:48 -08:00
|
|
|
Thd : ('a -> 'b, 'a) ty_sel
|
|
|
|
| Ttl : ('b -> 'c, 'd) ty_sel -> ('a -> 'b -> 'c, 'd) ty_sel
|
2011-12-27 18:22:38 -08:00
|
|
|
and (_, _) ty_case =
|
2011-11-24 01:02:48 -08:00
|
|
|
TCarg : ('b, 'a) ty_sel * ('a, 'e) ty -> ('e, 'b) ty_case
|
|
|
|
| TCnoarg : ('b, noarg) ty_sel -> ('e, 'b) ty_case
|
2011-12-27 18:22:38 -08:00
|
|
|
# type _ ty_env =
|
2011-11-24 01:02:48 -08:00
|
|
|
Enil : unit ty_env
|
|
|
|
| Econs : ('a, 'e) ty * 'e ty_env -> ('a -> 'e) ty_env
|
2011-12-27 18:22:38 -08:00
|
|
|
# type (_, _) eq = Eq : ('a, 'a) eq
|
2011-11-24 01:02:48 -08:00
|
|
|
val eq_sel : ('a, 'b) ty_sel -> ('a, 'c) ty_sel -> ('b, 'c) eq option = <fun>
|
|
|
|
val get_case :
|
2011-12-27 00:52:45 -08:00
|
|
|
('b, 'a) ty_sel ->
|
|
|
|
(string * ('e, 'b) ty_case) list -> string * ('a, 'e) ty option = <fun>
|
2011-11-24 01:02:48 -08:00
|
|
|
# type variant =
|
|
|
|
VInt of int
|
|
|
|
| VString of string
|
|
|
|
| VList of variant list
|
|
|
|
| VOption of variant option
|
|
|
|
| VPair of variant * variant
|
|
|
|
| VConv of string * variant
|
|
|
|
| VSum of string * variant option
|
|
|
|
val may_map : ('a -> 'b) -> 'a option -> 'b option = <fun>
|
2011-12-27 00:52:45 -08:00
|
|
|
val variantize : 'e ty_env -> ('a, 'e) ty -> 'a -> variant = <fun>
|
|
|
|
# val devariantize : 'e ty_env -> ('t, 'e) ty -> variant -> 't = <fun>
|
2011-11-24 01:02:48 -08:00
|
|
|
# val wrap_A : ('a, 'b) ty -> ([ `A of 'a ], 'b) ty = <fun>
|
|
|
|
# val ty : ('a, ([ `A of ('a * 'b) option ] as 'b) -> 'c) ty -> ('b, 'c) ty =
|
|
|
|
<fun>
|
|
|
|
# val v : ([ `A of (int * 'a) option ] as 'a) -> variant = <fun>
|
|
|
|
# val x : variant =
|
|
|
|
VConv ("`A",
|
|
|
|
VOption
|
|
|
|
(Some
|
|
|
|
(VPair (VInt 1,
|
|
|
|
VConv ("`A",
|
|
|
|
VOption (Some (VPair (VInt 2, VConv ("`A", VOption None)))))))))
|
|
|
|
# val triple :
|
|
|
|
('a, 'b) ty -> ('c, 'b) ty -> ('d, 'b) ty -> ('a * 'c * 'd, 'b) ty = <fun>
|
|
|
|
val v : variant =
|
|
|
|
VConv ("Triple", VPair (VString "A", VPair (VInt 2, VInt 3)))
|
|
|
|
# val ty_abc : ([ `A of int | `B of string | `C ], 'a) ty =
|
|
|
|
Sum
|
|
|
|
{sum_proj = <fun>;
|
|
|
|
sum_cases =
|
|
|
|
[("A", TCarg (Thd, Int)); ("B", TCarg (Ttl Thd, String));
|
|
|
|
("C", TCnoarg (Ttl (Ttl Thd)))];
|
|
|
|
sum_inj = <fun>}
|
|
|
|
# val a : [ `A of int | `B of string | `C ] = `A 3
|
|
|
|
type 'a vlist = [ `Cons of 'a * 'a vlist | `Nil ]
|
2011-12-27 00:52:45 -08:00
|
|
|
val ty_list : ('a, 'e) ty -> ('a vlist, 'e) ty = <fun>
|
2011-11-24 01:02:48 -08:00
|
|
|
val v : variant =
|
|
|
|
VSum ("Cons",
|
|
|
|
Some
|
|
|
|
(VPair (VInt 1, VSum ("Cons", Some (VPair (VInt 2, VSum ("Nil", None)))))))
|
2011-12-27 18:22:38 -08:00
|
|
|
# type (_, _) ty =
|
2011-11-24 01:02:48 -08:00
|
|
|
Int : (int, 'c) ty
|
|
|
|
| String : (string, 'd) ty
|
|
|
|
| List : ('a, 'e) ty -> ('a list, 'e) ty
|
|
|
|
| Option : ('a, 'e) ty -> ('a option, 'e) ty
|
|
|
|
| Pair : (('a, 'e) ty * ('b, 'e) ty) -> ('a * 'b, 'e) ty
|
|
|
|
| Var : ('a, 'a -> 'e) ty
|
|
|
|
| Rec : ('a, 'a -> 'e) ty -> ('a, 'e) ty
|
|
|
|
| Pop : ('a, 'e) ty -> ('a, 'b -> 'e) ty
|
|
|
|
| Conv : string * ('a -> 'b) * ('b -> 'a) * ('b, 'e) ty -> ('a, 'e) ty
|
|
|
|
| Sum : ('a -> string * 'e ty_dyn option) *
|
|
|
|
(string * 'e ty_dyn option -> 'a) -> ('a, 'e) ty
|
|
|
|
and 'e ty_dyn = Tdyn : ('a, 'e) ty * 'a -> 'e ty_dyn
|
|
|
|
val ty_abc : ([ `A of int | `B of string | `C ], 'e) ty = Sum (<fun>, <fun>)
|
|
|
|
# Characters 327-344:
|
|
|
|
| "Cons", Some (Tdyn (Pair (_, Var), (p : a * a vlist))) -> `Cons p)))
|
|
|
|
^^^^^^^^^^^^^^^^^
|
|
|
|
Error: This pattern matches values of type a * a vlist
|
|
|
|
but a pattern was expected which matches values of type
|
2012-10-10 02:38:03 -07:00
|
|
|
a#5 = ex#34 * ex#35
|
2011-12-27 18:22:38 -08:00
|
|
|
# type (_, _) ty =
|
2011-11-24 01:02:48 -08:00
|
|
|
Int : (int, 'd) ty
|
|
|
|
| String : (string, 'f) ty
|
|
|
|
| List : ('a, 'e) ty -> ('a list, 'e) ty
|
|
|
|
| Option : ('a, 'e) ty -> ('a option, 'e) ty
|
|
|
|
| Pair : (('a, 'e) ty * ('b, 'e) ty) -> ('a * 'b, 'e) ty
|
|
|
|
| Var : ('a, 'a -> 'e) ty
|
|
|
|
| Rec : ('a, 'a -> 'e) ty -> ('a, 'e) ty
|
|
|
|
| Pop : ('a, 'e) ty -> ('a, 'b -> 'e) ty
|
|
|
|
| Conv : string * ('a -> 'b) * ('b -> 'a) * ('b, 'e) ty -> ('a, 'e) ty
|
|
|
|
| Sum :
|
|
|
|
< cases : (string * ('e, 'b) ty_case) list;
|
|
|
|
inj : 'c. ('b, 'c) ty_sel * 'c -> 'a;
|
|
|
|
proj : 'a -> string * 'e ty_dyn option > -> ('a, 'e) ty
|
|
|
|
and 'e ty_dyn = Tdyn : ('a, 'e) ty * 'a -> 'e ty_dyn
|
2011-12-27 18:22:38 -08:00
|
|
|
and (_, _) ty_sel =
|
2011-11-24 01:02:48 -08:00
|
|
|
Thd : ('a -> 'b, 'a) ty_sel
|
|
|
|
| Ttl : ('b -> 'c, 'd) ty_sel -> ('a -> 'b -> 'c, 'd) ty_sel
|
2011-12-27 18:22:38 -08:00
|
|
|
and (_, _) ty_case =
|
2011-11-24 01:02:48 -08:00
|
|
|
TCarg : ('b, 'a) ty_sel * ('a, 'e) ty -> ('e, 'b) ty_case
|
|
|
|
| TCnoarg : ('b, noarg) ty_sel -> ('e, 'b) ty_case
|
|
|
|
# val ty_abc : ([ `A of int | `B of string | `C ], 'e) ty = Sum <obj>
|
|
|
|
type 'a vlist = [ `Cons of 'a * 'a vlist | `Nil ]
|
2011-12-27 00:52:45 -08:00
|
|
|
val ty_list : ('a, 'e) ty -> ('a vlist, 'e) ty = <fun>
|
2011-11-24 01:02:48 -08:00
|
|
|
# * * * * * * * * *
|