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
Re: [Caml-list] type var in functor instance?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-09-20 (20:22)
From: Jon Harrop <jon@j...>
Subject: Re: [Caml-list] Core library (was: type var in functor instance?)
On Monday 20 September 2004 16:43, skaller wrote:
> > - to make an unfunctorized version of Set that uses,
> >   thus polymorphic
> This is already in the standard distro for Hashtbl.
> Why not for Set and Map as well? Why is this
> unsatisfactory?

You mean Hashtbl uses a polymorphic hash?

I think it would be productive to factor the tree out of set and map.

What if someone released backwards-compatible replacement modules for List, 
Array, Set, Map etc. which implemented this stuff? Then package maintainers 
could replace them if they liked the alternative implementations and coders 
could assume their existence. Maybe.

> I actually use heaps of Hashtbl of polymorphic kind
> and am ready to switch some over to an functor instance
> with key type int -- most of my tables use int keys
> and I hope to gain some performance and reasoning ability.

IMHO, hash tables are a bit less safe than sets and maps because hash tables 
make it easier to apply a structure-based polymorphic function incorrectly, 
e.g. to many abstract types, when a semantically meaningful (e.g. comparison) 
function should be used. For example, I don't think a hash table of sets 
would be very useful...

This strikes me as an important way to screw up ML programs and, consequently, 
it would be nice to address this. I've been trying to think of a solution but 
all I've come up with is: you could enforce the use of an appropriate 
comparison by making everything an object with its own compare method. But 
then you're going back to dynamic typing. Perhaps phantom types could do 


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