id,summary,reporter,owner,description,type,status,priority,milestone,component,version,resolution,keywords,cc,os,architecture,failure,difficulty,testcase,blockedby,blocking,related
1038,selector thunks not working? space leak in standard example,tullsen@…,simonmar,"I thought that GHC evaluates ""THUNK_SELECTORS"" and thus eliminates the space leak in this infamous example [Hughes83][Wadler87][Sparud93]:
{{{
module Main where

surprise xs = b1 ++ [0,0] ++ b2
              where
              (b1,b2) = break (==0) xs

strictFromTo :: Int -> Int -> [Int]
strictFromTo i m = takeWhile (<= m) $ strictFrom i

strictFrom :: Int -> [Int]
strictFrom x = let x' = x + 1 in seq x' $ x' : strictFrom x'
        
main = print (length $ surprise $ strictFromTo (-1000000) 1)
       -- space leak, w/ or w/o optimization
main2 = print (length $ strictFromTo (-1000000) 1)
       -- runs in constant space, w/ or w/o optimization
}}}
However, this program does not run in constant space, even with -O2.  
I get the same results on
 GHC6.6  Mac OS X  Intel
 GHC6.2.1 Linux Intel
 GHC6.4.1 Linux Intel",bug,closed,normal,6.8.1,Runtime System,6.6,fixed,,,Unknown/Multiple,x86,,Unknown,,,,
