Proposal: Non-allocating way to iterate over a Data.Map: traverseWithKey_

Milan Straka fox at ucw.cz
Tue Aug 6 16:20:09 CEST 2013


Hi Ryan,

> -----Original message-----
> From: Ryan Newton <rrnewton at gmail.com>
> Sent: 6 Aug 2013, 09:51
>
> Milan, why does it bother you that there is no specified order?  I'm
> perfectly happy as long as its deterministic on a particular machine.

it seems to me that having specified order (e.g., ascending) is more
useful, if it can be provided. If I use traverseWithKey_ to process the
elements (e.g., write them to a file, add them to other structure, send
across the network), it seems to me that process them in ascending order
is more beneficial that iterating over them in some order specified by
the shape of the structure.

I am not saying that having an operation without defined order is
useless, only that operation with ascending order seems more useful to
me.

> Aren't we already used to using Data.Map.toList and Data.Set.toList
> where order is not specified?

Well, we also have toAscList and toDescList. Moreover, toList is actually
toAscList, so I wonder how many libraries would be affected if toList
started returning the elements in some random order :)



My point is this -- if we think having an Applicative / Monadic
iteration which does not allocate is useful, I believe we should also
provide such an iteration in ascending order.


Cheers,
Milan




More information about the Libraries mailing list