Proposal: Make intersperse lazier
duncan.coutts at googlemail.com
Thu Sep 16 11:08:08 EDT 2010
On 16 September 2010 15:39, Daniel Fischer <daniel.is.fischer at web.de> wrote:
> The current implementation of Data.List.intersperse causes a space leak
> under certain not uncommon circumstances.
> Trac ticket: http://hackage.haskell.org/trac/ghc/ticket/4282
> The proposed implementation,
> changes the semantics from
> intersperse (x : _|_) = _|_
> intersperse (x : _|_) = x : _|_
intersperse sep (x : _|_) = x : _|_
We would also need to change intercalate to match:
intercalate sep (x : _|_) = x ++ _|_
Note that the current definition of intercalate in the base package
will not need to change because it is defined in terms of intersperse,
but its strictness specification does change.
Assuming the proposal is updated with the corresponding change to
intercalate, then I support the proposal. It is in the spirit of the
Haskell98 List module for list functions to be as lazy as possible
(except there are good reasons to be stricter, e.g. as in splitAt).
Incidentally, the lazier version is also slightly more efficient.
More information about the Libraries