Proposal: Make intersperse lazier
daniel.is.fischer at web.de
Thu Sep 16 11:41:14 EDT 2010
On Thursday 16 September 2010 17:08:08, Duncan Coutts wrote:
> On 16 September 2010 15:39, Daniel Fischer <daniel.is.fischer at web.de>
> > 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 : _|_) = _|_
> > to
> > intersperse (x : _|_) = x : _|_
> You mean:
> intersperse sep (x : _|_) = x : _|_
Oops, of course.
> 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
You mean, also mention the consequences for intercalate explicitly?
Or something more/else?
> 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