Version française
Home     About     Download     Resources     Contact us    
Browse thread
Type abstraction and (polymorphic) equality
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alain Frisch <Alain.Frisch@i...>
Subject: Re: [Caml-list] Type abstraction and (polymorphic) equality
padiolea@irisa.fr wrote:
> I know many people who have "defunctorized" the Map and Set modules
> and hardcoded a call to the generic compare  to be able to use
> Set and Map as easily as you use List.
> Even with this generic compare those Set and Map seems quite good
> enough (and far better of course that using List for representing
> sets and associations).

By "good", you mean "efficient", I guess.  I understand that easy 
solutions are sometimes good enough. My claim is that in this case, the 
easy solution is also a risky one. An example of how using the easy 
solution can bite you:

http://pauillac.inria.fr/bin/caml-bugs/fixed?id=2916


>>You know better than the compiler and the runtime
>>system how your data is to be compared,
> 
> 
> Well then you are perhaps agree with the C++ folks who think
> that they better know how to manage memory than the compiler and runtime
> system.

No, I don't agree. I know that the runtime system can help me managing 
the memory. There are exceptions (I know that I need to clear explicitly 
some global tables or references to avoid memory leaks), but in general, 
the runtime system does a good job and the GC behavior is always safe, 
so there is no problem using it.

Concerning comparisons, you currently need to choose either to rely 
purely on the generic function or to implement a custom one yourself.
You cannot use your knowledge to improve the automatic behavior. The 
generic comparison is not always safe, so when you write polymorphic 
code, you simply cannot assume that generic comparison is ok.

(I don't claim that the current situation is satisfactory, only that 
considering it, generic comparison is too dangerous.)



>>There are several tools to
>>generate automatically comparison functions from type declarations.
> 
> 
> Which one ? I know Tywith but it is not in the standard distribution
> and it requires camlp4 and there is sometimes some annoying
> behaviour when you use camlp4 (such as backtraces that points
> to wrong information)

http://www.pps.jussieu.fr/~maurel/programmation/


-- Alain