Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
hashtables for mutable records
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: hashtables for mutable records
From: "Coscoy, Yann" <>

> I want to do an hashtable on mutable and polymorphic records. Standard
> module Hashtbl is not suitable because:
>   - Hashtbl.HashType doesn't accept polymorphic types.
>   - Hashtbl.hash is susceptible to setups of a mutable fields.

The standard functorial solution would be to define a new functor:

type 'a polyref = {mutable data: 'a; id: int}

module PolyHash(T : sig type t end) =
      type t = T.t polyref
      let equal a b = ( =
      let hash a =

module IntHash = PolyHash(struct type t = int end)
module BoolHash = PolyHash(struct type t = bool end)

The only dificulty with such an approach is that you must use
different functions for different hashtables.
If you want to define new polymorphic functions using these
hashtables, you must again put them in a functor.


Jacques Garrigue      Kyoto University     garrigue at
		<A HREF=>JG</A>