Proposal: Non-allocating way to iterate over a Data.Map: traverseWithKey_
Henning Thielemann
lemming at henning-thielemann.de
Tue Jul 2 21:57:58 CEST 2013
On Tue, 2 Jul 2013, Ryan Newton wrote:
> Hi all,
> Thanks for the responses. I want to go through and make sure I understand these.
>
> --------------------------------------------------------
> First, Henning, won't both of these allocate in proportion to the size of the map?
>
> Map.foldrWithKey (\k a -> f k a >>) (return ())
> Foldable.sequence_ . Map.mapWithKey f
>
> In particular, will the compiler be able to avoid allocating when building up that large monadic computation
> in the foldrWithKey?
Since it is a foldr, the first action can be run without knowing the
following ones. That is, at no time all actions must be allocated.
More information about the Libraries
mailing list