mapM/concatMapMy

Sengan Baring-Gould senganb@ia.nsc.com
Wed, 18 Oct 2000 22:09:21 -0600 (MDT)


> 
> 
> senganb@ia.nsc.com (Sengan Baring-Gould) wrote:
> 
> > mapM seems to be a memory hog (and thus also concatMapM).
> > In the following eg:
> > 
> > > main = mapM print ([1..102400] :: [Integer])
> > 
> > memory usage climbs to 1.6M with ghc and needs -K20M
> 
> As a guess: since 'mapM print ([1..102400] :: [Integer])'
> has type 'IO [()]', perhaps the result of the IO operation --
> a list of 100K empty tuples -- is the culprit, even though
> the result is never used.
> 
> Does 'mapM_ print ... ' (:: IO ()) perform any better?

Yes, but in the following eg

> main = print $ sum x
> x = _scc_ "x" [1..102400] :: [Integer]

x takes 1M allocations, and I would think that () would be smaller than
an Integer. Therefore I'm not sure that is the reason. The sum is there to
force the evaluation.

Sengan