Browse thread
Q: hashtables of parametrized types in Ocaml?
-
Basile STARYNKEVITCH
-
Mark Hayden
- Christian Boos
-
Mark Hayden
[
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: | Christian Boos <boos@a...> |
| Subject: | Re: Q: hashtables of parametrized types in Ocaml? |
Mark Hayden writes:
>
> Here is a similar example that works for me.
> This is for hash tables that use MD5 digest
> strings for keys.
>
> --Mark
> <<.mli and .ml snipped>>
Hello,
I don't think this was an example similar to the original post.
What Basile needed was a parametrized type for the key type:
He wrote:
> >I tried
> >
> > module SymbolHashtbl =
> > Hashtbl.Make(struct
> > type t = 'a asymbol_t
> > let equal = (==)
> > let hash = symhash
> > end)
> >
> >but it doesn't work! How can I achieve an equivalent result? Of course
> > <<...>>
> >Perhaps a double functor is the answer, but I can't figure it out!
I think his idea of a "double functor" is the good one.
Try:
module MakeHashtbl (S : sig type v end) =
Hashtbl.Make
(struct
type t = S.v asymbol_t
let equal = (==)
let hash = symhash
end)
and then later:
module NodeSymbolHashtbl = MakeHashtbl (sig type v = node_t end)
-- Christian