Space leak question

Will Ness will_n48 at yahoo.com
Wed Jul 27 09:49:42 CEST 2011


Will Ness <will_n48 <at> yahoo.com> writes:

> 
> Bertram Felgenhauer <bertram.felgenhauer <at> googlemail.com> writes:
> 
> > 
> > Hi Will,
> > > in reformulation of a code with no space leak, the leak reappeares.
> > > 
> > This is entirely expected. (.....)
> > 
> >  {-# OPTIONS_GHC -O2 #-}
> >  primes :: [Int]
> >  primes = 2 : g (fix g)
> >   where
> >    g xs = (3:) . (odds `minus`)
> >                . foldi (\(x:xs) -> (x:) . union xs)
> >                . map (\x-> [x*x, x*x+2*x..]) $ xs
> >    odds = [5,7..]
> > 
> 
  CORRECTION: just with "gaps" (but not the other ones), changing the "g" 
  function from composed pieces into a "normal" code, it did it! (probably 
  some ghc version-specific stuff at play):
  
    g xs = 3 : gaps 5
                ( foldi (\(x:xs) -> (x:) . union xs)
                  [[x*x, x*x+2*x..] | x <- xs] )
  

addition: with

  gaps k xs = minus [k,k+2..] xs

it also runs without the space leak, but with

  gaps k = minus [k,k+2..]

the leak reappears.

(?)


















More information about the Glasgow-haskell-users mailing list