Data.Map.unzip?

Henning Thielemann lemming at henning-thielemann.de
Sat Dec 6 11:08:08 UTC 2014


On Sat, 6 Dec 2014, Joachim Breitner wrote:

> Am 6. Dezember 2014 10:25:03 MEZ, schrieb Andreas Abel <abela at chalmers.se>:
>> On 05.12.2014 22:43, Joachim Breitner wrote:
>>> did anyone else ever wanted to have a function
>>>
>>> Data.Map.unzip :: Map k (a, b) -> (Map k a , Map k b)
>>
>> Yes, I wanted it, and was annoyed by its absence, and the fact that I
>> had to fall back to the  <fmap fst , fmap snd>  solution (for
>> efficiency
>> reasons).
>
> although I wonder how big the difference would be. At least both 
> versions will re-use the tree-structure. It probably depends on how its 
> used...

Consider the following example

   let (bigs,smalls) = unzip mix
   in  do f bigs
          g smalls

'bigs' contains a great amount of data, and thus you prefer that it can be 
garbage collected as 'f' consumes it. If 'unzip' is actually

  (fmap fst mix, fmap snd mix)

then 'mix' (and thus all big data) will be kept in memory until 'g' starts 
processing.


More information about the Libraries mailing list