Commit c3c35334 authored by Daniel Fischer's avatar Daniel Fischer

FIX #4334

Make selector thunks visible to GHC to fix a space leak in lines.
parent 2620fbe0
......@@ -1038,10 +1038,23 @@ product l = prod l 1
-- characters. The resulting strings do not contain newlines.
lines :: String -> [String]
lines "" = []
-- Somehow GHC doesn't detect the selector thunks in the below code,
-- so s' keeps a reference to the first line via the pair and we have
-- a space leak (cf. #4334).
-- So we need to make GHC see the selector thunks with a trick.
lines s = cons (case break (== '\n') s of
(l, s') -> (l, case s' of
[] -> []
_:s'' -> lines s''))
cons ~(h, t) = h : t
lines s = let (l, s') = break (== '\n') s
in l : case s' of
[] -> []
(_:s'') -> lines s''
-- | 'unlines' is an inverse operation to 'lines'.
-- It joins lines, after appending a terminating newline to each.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment