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
15 with type t = (elt, Node.t) node
18 type t = (elt, Node.t) node
22 | Cons(e1, l1), Cons(e2, l2) -> e1 == e2 && l1 == l2
28 HASHINT3 (PRIME1, Uid.to_int (H.uid e), Uid.to_int (Node.uid l))
35 let rec sorted_cons e l =
36 match l.Node.node with
37 | Nil -> Node.make (Cons(e, l))
40 then Node.make (Cons(e, l))
41 else Node.make (Cons(x, sorted_cons e ll))
46 let cons ?(sorted=true) e l =
47 if sorted then sorted_cons e l else cons e l
49 let hd = function { Node.node = Cons(e, _); _ } -> e | _ -> failwith "hd"
50 let tl = function { Node.node = Cons(_, l); _ } -> l | _ -> failwith "tl"
53 let rec loop acc l = match l.Node.node with
55 | Cons (a, aa) -> loop (f a acc) aa
60 let rec loop l = match l.Node.node with
62 | Cons(a, aa) -> cons (f a) (loop aa)
67 let rec loop l = match l.Node.node with
69 | Cons(a,aa) -> (f a);(loop aa)
73 let rev l = fold cons l nil
74 let rev_map f l = fold (fun x acc -> cons (f x) acc) l nil
75 let length l = fold (fun _ c -> c+1) l 0
77 match l.Node.node with
79 | Cons (x, ll) -> x == e || mem e ll
83 module Make = Builder(Hcons.Make)
84 module Weak = Builder(Hcons.Weak)