Proposal: Make intersperse lazier

Duncan Coutts duncan.coutts at
Thu Sep 16 11:08:08 EDT 2010

On 16 September 2010 15:39, Daniel Fischer < at> wrote:
> The current implementation of Data.List.intersperse causes a space leak
> under certain not uncommon circumstances.
> Trac ticket:
> The proposed implementation,

> changes the semantics from
> intersperse (x : _|_) = _|_
> to
> intersperse (x : _|_) = x : _|_

You mean:

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 mailing list