Ord instance for Data.Map?

Johannes Waldmann waldmann at imn.htwk-leipzig.de
Wed Apr 18 17:11:54 EDT 2007


Isaac Dupree wrote:

> And then what do you do with (set1 `union` set2) where they have
> different comparators? 

Nice question! Looking at the JDK source,
in the TreeSet implementation of Collection.addAll (..),
they actually compare the comparator objects
( with .equals() , so you can define that as you like )

>  But you can always directly have the (key -> key -> Ordering) function
> be part of your data structure for the same effect,

Yes, I meant that function when I said "the Ord dictionary".
Sorry for confusion.

> and then you can see
> all the problems involved (serialization, interactions and comparisons
> between maps, etc.).

Well, of course the Haskell system cannot serialize or compare
(anonymous) functions.

In Java land, as the compare function is attached
to a Comparator object, the burden of serialization
is on the programmer.
(also of writing the equality test mentioned above).
Looks rather sensible to me, under the circumstances.

Best regards, J. W.




More information about the Libraries mailing list