Unordered map
Neil Mitchell
ndmitchell at gmail.com
Tue Jul 29 14:05:12 EDT 2008
Hi
> The other way to make the library more consistent, perhaps, would be
> to simply move the Ord requirement up to that data structure: that is,
> make it Ord k => Map k a, and then have a new data structure like
> UnorderedMap (or, to use a more standard term, Dictionary).
Have you tried to do this? You get errors all over the place, the
monomorphism restriction kicks in, and it goes really wrong. Consider
Data.Map.empty, you'd have to pass an Ord dictionary for the key,
which often isn't known at that point. Suddenly the code:
newMap = Data.Map.empty
Stops working! Having too much polymorphism at random places breaks it.
In essence, putting a context on a data type is a really bad idea.
Haskell's solution with Data.Map is perfectly fine, and seems logical
once you realise that its just the Haskell encoding of Ord k => Map k
a
Thanks
Neil
More information about the Libraries
mailing list