Proposal: Make intersperse lazier (update)

Daniel Fischer daniel.is.fischer at web.de
Thu Sep 16 11:53:05 EDT 2010


On Thursday 16 September 2010 16:39:56, Daniel Fischer 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,
>
> intersperse             :: a -> [a] -> [a]
> intersperse _   []      = []
> intersperse sep (x:xs)  = x : go xs
>   where
>     go []     = []
>     go (y:ys) = sep : y : go ys
>
> changes the semantics from
>
> intersperse sep (x : _|_) = _|_
>
> to
>
> intersperse sep (x : _|_) = x : _|_
>
> apart from that, I think only the run-time behaviour is changed.
>
> Period of discussion: Two weeks, until 30 Sep. 2010.
>
> Cheers,
> Daniel

As Duncan pointed out, I've omitted to make explicit that this change would 
also affect Data.List.intercalate, changing its behaviour from

intercalate sep (xs : _|_) = _|_

to

intercalate sep (xs : _|_) = xs ++ _|_

I would like to include that explicitly in the proposal.



More information about the Libraries mailing list