* [Caml-list] Polymorphic hash tables
@ 2015-02-09 14:21 Sébastien Hinderer
2015-04-14 12:12 ` Goswin von Brederlow
0 siblings, 1 reply; 2+ messages in thread
From: Sébastien Hinderer @ 2015-02-09 14:21 UTC (permalink / raw)
To: caml-list
Hi,
Is there a way to just replace OCaml's standard hash function for some
tables?
Here is an example:
module MyHashedType : Hashtbl.HashedType = struct
type t
let my_n = 20
let my_m = 30
let equal = (=)
let hash = Hashtbl.hash_param my_n my_m
end
module MyHashtbl = Hashtbl.Make(MyHashedType)
let (mytbl : int MyHashtbl.t) = MyHashtbl.create 100
With this example polymorphism seems to be lost and the compiler does
not accept something like
type t = 'a
to retrieve a generic type as for the standard hash tables.
Any suggestion?
Thanks a lot.
Sébastien.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Polymorphic hash tables
2015-02-09 14:21 [Caml-list] Polymorphic hash tables Sébastien Hinderer
@ 2015-04-14 12:12 ` Goswin von Brederlow
0 siblings, 0 replies; 2+ messages in thread
From: Goswin von Brederlow @ 2015-04-14 12:12 UTC (permalink / raw)
To: caml-list
On Mon, Feb 09, 2015 at 03:21:07PM +0100, Sébastien Hinderer wrote:
> Hi,
>
> Is there a way to just replace OCaml's standard hash function for some
> tables?
>
> Here is an example:
>
> module MyHashedType : Hashtbl.HashedType = struct
> type t
> let my_n = 20
> let my_m = 30
> let equal = (=)
> let hash = Hashtbl.hash_param my_n my_m
> end
>
> module MyHashtbl = Hashtbl.Make(MyHashedType)
>
> let (mytbl : int MyHashtbl.t) = MyHashtbl.create 100
>
> With this example polymorphism seems to be lost and the compiler does
> not accept something like
> type t = 'a
> to retrieve a generic type as for the standard hash tables.
>
> Any suggestion?
>
> Thanks a lot.
> Sébastien.
You have to use a functor there.
MfG
Goswin
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-04-14 12:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-09 14:21 [Caml-list] Polymorphic hash tables Sébastien Hinderer
2015-04-14 12:12 ` Goswin von Brederlow
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox