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
[Caml-list] polymorphic modules in classes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-04-17 (02:29)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] polymorphic modules in classes
From: Axel Simon <>

> When I compile, I get "Unbound type constructor a'" for the line which 
> introduces stored, although it works with int.

This just looks like a typo: this should be 'a (a type variable), not
a' (an identifier). When fixed, your program is accepted.

> I guess there are many 
> other problems with my solution: PhysEq.t is abstract and PhysHashtbl.key 
> is not bound to any type. How do I solve all this?

This one is a much more serious problem, and appears frequently on
this list.
The only solution currently is to copy the Hashtbl module, replacing
key by 'a key, and 'a t by ('b,'a) t.

A simpler workaround is to define a functor producing your class.

module Make(T : sig type t end) = struct
  module PhysEq = struct
    type t = T.t
    let equal = (==)
    let hash  = H.hash

  module PhysHashtbl : H.S with type key = T.t = H.Make(PhysEq)

  class ['a] bulkWriter ((fname, wr) : string * (out_channel -> 'a -> unit))  =
    let outCh = open_out_bin fname
    and stored   : ('a PhysHashtbl.t) = (PhysHashtbl.create 100)
    in object
     (* something here *)   

Then you can create a class for every type you need.

But I'm not sure exactly of what you intend to use your hash table
for. Does it really need to handle many types?

Jacques Garrigue

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: