Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] how to open types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Olivier Andrieu <andrieu@i...>
Subject: Re: [Caml-list] how to open types
 pan deng [Monday 4 November 2002] :
 >
 > I want to use hashtable on my objects which all has a
 > method get_string:string.
 > but i can only write the code like these:
 > 
 > module SeqHashType =
 > struct 
 >   type  t= <get_string:string >
 >   let equal s1  s2 = (String.uppercase s1#get_string
 > =String.uppercase  s2#get_string )
 >   let hash s = Strex.hash s#get_string  
 > end
 > module SeqHashtbl = Hashtbl.Make (SeqHashType)
 > 
 > surely it is not what i want . i have tried 
 > type t= <get_string:string ; ..>
 > 
 > but i can not complie it , the complier says Unbound
 > ..

Yes, "open" object type have an implicit type parameter that you have
to specify in the definition :

  type 'a t = 'a constraint <get_string: string; ..>

 > then how to open the type <get_string:string> in the
 > module SeqHashType ?
 > or it can not be opened at this situation ?

You cannot because in the module signature Hashtbl.HashedType, type t
isn't polymorph.

I guess the solution would be to use

  type t = <get_string:string>

and to coerce your objects to this

  (o :> SeqHashType.t)

-- 
   Olivier
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners