
27 Sep
2010
27 Sep
'10
5:40 p.m.
Daniel Fischer wrote:
Proposal: A stricter implementation of lines. Reason: The current implementation causes a space leak Ticket: http://hackage.haskell.org/trac/ghc/ticket/4334
I propose the following combinator approach as an alternative: lines :: String -> [String] lines = map (takeWhile (/= '\n')) . takeWhile (not . null) . iterate (drop 1 . dropWhile (/= '\n')) GHC fuses that into a tight loop. So in addition to solving the space leak, it is faster and uses less heap than both the existing implementation and Daniel's proposal. It is also cleaner and easier to read, in my opinion. Thanks, Yitz