5 module type HConsBuilder =
6 functor (H : Common_sig.HashedType) -> Hcons.S with type data = H.t
8 module Builder (HCB : HConsBuilder) (H : Hcons.Abstract) :
9 S with type elt = H.t =
13 module rec Node : Hcons.S with type data = Data.t = HCB(Data)
14 and Data : Common_sig.HashedType with type t = (elt, Node.t) node =
16 type t = (elt, Node.t) node
20 | Cons(e1, l1), Cons(e2, l2) -> e1 == e2 && l1 == l2
25 | Cons(e, l) -> HASHINT3 (PRIME1, Uid.to_int (H.uid e), Uid.to_int (Node.uid l))
32 let rec sorted_cons e l =
33 match l.Node.node with
34 | Nil -> Node.make (Cons(e, l))
37 then Node.make (Cons(e, l))
38 else Node.make (Cons(x, sorted_cons e ll))
43 let cons ?(sorted=true) e l =
44 if sorted then sorted_cons e l else cons e l
46 let hd = function { Node.node = Cons(e, _); _ } -> e | _ -> failwith "hd"
47 let tl = function { Node.node = Cons(_, l); _ } -> l | _ -> failwith "tl"
50 let rec loop acc l = match l.Node.node with
52 | Cons (a, aa) -> loop (f a acc) aa
57 let rec loop l = match l.Node.node with
59 | Cons(a, aa) -> cons (f a) (loop aa)
64 let rec loop l = match l.Node.node with
66 | Cons(a,aa) -> (f a);(loop aa)
70 let rev l = fold cons l nil
71 let rev_map f l = fold (fun x acc -> cons (f x) acc) l nil
72 let length l = fold (fun _ c -> c+1) l 0
74 match l.Node.node with
76 | Cons (x, ll) -> x == e || mem e ll
80 module Make = Builder(Hcons.Make)
81 module Weak = Builder(Hcons.Weak)