export toDescList from Data.Map

Christian Maeder Christian.Maeder at dfki.de
Wed Sep 24 04:46:18 EDT 2008


Hallo Evan,

If it is really such a performance difference the functions should be
exported by all means. (Another work-around might by to inverse the
order of the keys, but that'll be unnatural at least for Int keys.)

Obviously, I rarely have 1 million elements in my maps.

Evan Laforge wrote:
>>> That's one of the things I was asking... how do you obtain toDescList
>>> without foldlWithKey?  And for me, since since the order of the keys
>>> is important (say points in time), the order of the fold matters a
>>> great deal.
>> I thought of "reverse . toList". Maybe the folding functions are not
>> needed at all (or only short cuts):
> 
> Ah, well if I really didn't care about performance, then I wouldn't
> use Map at all, just an unsorted [(k, v)].  But it's sort of awkward
> for the GUI to freeze for a second (yes, it really does take that
> long) while haskell reverses a 1 million element list just to get the
> first 3 elements (and does so many times)...

findMax (deleteFinMax) for the highest 3 elements would be faster then.

>> foldlWithKey f z = foldl (\ b (k, v) -> f b k v) z . toList
> 
> This is equivalent to reverse, isn't it?  It also takes a second or so
> (well, once I add a prime of course, without the prime it sends the
> whole system into OOM molasses).

Yes, but folding is linear anyway (if the whole result is needed).

Cheers Christian


More information about the Libraries mailing list