#4334: Make lines stricter to fix space leak
----------------------------------+-----------------------------------------
Reporter: daniel.is.fischer | Owner:
Type: proposal | Status: new
Priority: normal | Milestone: Not GHC
Component: libraries/base | Version: 6.12.3
Keywords: lines, space leak | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: Other
----------------------------------+-----------------------------------------
Comment(by daniel.is.fischer):
For GHC from 6.10 through HEAD, we can get non-leaking behaviour without
changing the strictness properties of `lines`:
{{{
lines :: String -> [String]
lines "" = []
lines s = cons $ case break (== '\n') s of
(l, s') -> (l, case s' of
[] -> []
_:s'' -> lines s'')
-- uncurry isn't available in Data.List
cons :: (a,[a]) -> [a]
cons ~(x,xs) = x : xs
}}}
Since it is not necessary to change the strictness properties, I favour
this over the original proposal.
Note however that in jhc-0.7.6 this leaks memory (as does the original
implementation).[[BR]]
Also note that the fix is fragile, a change to the garbage collector can
break it easily.[[BR]]
Nevertheless, I prefer a fragile temporary fix over no fix at all.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4334#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs