Make lines stricter to fix a space leak

Duncan Coutts duncan.coutts at googlemail.com
Mon Oct 4 14:15:07 EDT 2010


On 24 September 2010 15:21, Daniel Fischer <daniel.is.fischer at web.de> wrote:
> Proposal: A stricter implementation of lines.
>
> Reason: The current implementation causes a space leak (cf.
> http://homepages.inf.ed.ac.uk/wadler/papers/leak/leak.ps), at least in GHC.
>
> The proposed implementation fixes the leak at the small cost of being
> stricter if the first _|_ in the String is the first character of a line.
>
> Discussion period: Three weeks, until 15th October (because of ICFP).
>
> Ticket: http://hackage.haskell.org/trac/ghc/ticket/4334


My gut instinct is that we should not make lines stricter. Generally
the list library is as lazy as possible, except when there are
compelling reasons otherwise. I am not yet convinced that this
proposal meets that standard.

Have we thought about the opposite issue, that there may be programs
that rely on the current non-strict version for correctness or memory
behaviour? We currently have an open proposal on making intersperse
less strict because it caused practical problems (unexpected memory
behaviour).

There's also an issue of consistency with other functions in the list
library. The lines function is similar in many ways to group /
groupBy, and with the proposed change the strictness properties of
these functions would be inconsistent. Such inconsistency has a cost
in terms of programmers being able to predict and reason about
strictness and space use (simply because if its inconsistent then it
is harder to remember).

The strictness of lines is pretty subtle. I think it would help our
discussion if people reading this thread look at the strictness
properties given in the ticket.

Duncan


More information about the Libraries mailing list