Browse thread
Defining type that requires hashtables with recursive definition
-
Hugo Ferreira
-
Jacques Carette
- Thomas Gazagnaire
- Hugo Ferreira
-
Jacques Carette
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Thomas Gazagnaire <ocaml@g...> |
| Subject: | Re: [Caml-list] Defining type that requires hashtables with recursive definition |
or if you really want to define your own equality, you can use recursive
modules:
module rec H : Hashtbl.HashedType =
struct
type node =
| Node of node J.t
| Leaf of int
type t = node
let equal (e1:node) (e2:node) = (==) e1 e2
let hash (e:node) = Hashtbl.hash e
end
and J : Hashtbl.S = Hashtbl.Make( H )
2009/1/19 Jacques Carette <carette@mcmaster.ca>
> Hugo Ferreira wrote:
>
>> I am attempting to define a type so:
>>
>> type node =
>> | Node of links
>> | Leaf of int
>>
>> And I want to implement links as a
>> hashtable whose keys and values are
>> also of type node.
>>
>
> type node =
> | Node of links
> | Leaf of int
> and links = (node, node) Hashtbl.t
>
> should do it.
>
> Jacques
>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>