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
22 module Make ( H : Hcons.S ) : S with type elt = H.t =
25 type 'a node = Nil | Cons of elt * 'a
26 module rec HNode : Hcons.S with type data = Node.t = Hcons.Make (Node)
27 and Node : Hashtbl.HashedType with type t = HNode.t node =
33 | Cons (a,aa), Cons(b,bb) -> (H.equal a b) && (HNode.equal aa bb)
37 | Cons(a,aa) -> HASHINT3(PRIME3,H.uid a, HNode.uid aa)
44 let equal = HNode.equal
46 let nil = HNode.make Nil
47 let cons a b = HNode.make (Cons(a,b))
49 match HNode.node a with
50 | Nil -> failwith "hd"
54 match HNode.node a with
55 | Nil -> failwith "tl"
60 let rec loop acc l = match HNode.node l with
62 | Cons(a,aa) -> loop (f a acc) aa
67 let rec loop l = match HNode.node l with
69 | Cons(a,aa) -> cons (f a) (loop aa)
74 let rec loop l = match HNode.node l with
76 | Cons(a,aa) -> (f a);(loop aa)
80 let rev l = fold cons l nil
81 let rev_map f l = fold (fun x acc -> cons (f x) acc) l nil
82 let length l = fold (fun _ c -> c+1) l 0