4 type 'a node = Nil | Cons of elt * 'a
8 val equal : t -> t -> bool
10 val node : t -> t node
11 val cons : elt -> t -> t
14 val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
15 val map : (elt -> elt) -> t -> t
16 val iter : (elt -> 'a) -> t -> unit
18 val rev_map : (elt -> elt) -> t -> t
21 module Make ( H : Hcons.S ) : S with type elt = H.t =
24 type 'a node = Nil | Cons of elt * 'a
25 module rec HNode : Hcons.S with type data = Node.t = Hcons.Make (Node)
26 and Node : Hashtbl.HashedType with type t = HNode.t node =
32 | Cons (a,aa), Cons(b,bb) -> (H.equal a b) && (HNode.equal aa bb)
36 | Cons(a,aa) -> HASHINT3(PRIME3,H.uid a, HNode.uid aa)
43 let equal = HNode.equal
45 let nil = HNode.make Nil
46 let cons a b = HNode.make (Cons(a,b))
48 match HNode.node a with
49 | Nil -> failwith "hd"
53 match HNode.node a with
54 | Nil -> failwith "tl"
59 let rec loop acc l = match HNode.node l with
61 | Cons(a,aa) -> loop (f a acc) aa
66 let rec loop l = match HNode.node l with
68 | Cons(a,aa) -> cons (f a) (loop aa)
73 let rec loop l = match HNode.node l with
75 | Cons(a,aa) -> (f a);(loop aa)
79 let rev l = fold cons l nil
80 let rev_map f l = fold (fun x acc -> cons (f x) acc) l nil