Ticket #1038 (closed bug: fixed)
selector thunks not working? space leak in standard example
| Reported by: | tullsen@… | Owned by: | simonmar |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.8.1 |
| Component: | Runtime System | Version: | 6.6 |
| Keywords: | Cc: | ||
| Operating System: | Unknown/Multiple | Architecture: | x86 |
| Type of failure: | Difficulty: | Unknown | |
| Test Case: | Blocked By: | ||
| Blocking: | Related Tickets: |
Description
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
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

