Proposal: Make intersperse lazier

Daniel Fischer daniel.is.fischer at web.de
Fri Sep 24 13:50:00 EDT 2010


On Friday 24 September 2010 17:55:15, Christian Maeder wrote:
> Am 24.09.2010 16:53, schrieb Daniel Fischer:
> > A good name for foo remains to be found.
>
>  prependToAll
>

Much better. I'm still not happy with the prepend, but insertBeforeEach 
isn't better and I can't think of anything convincing.

> > I don't like 'prepend' because prepend suggests only putting something
> > before a list (with the given type, it should be (:)) and not changing
> > anything inside.
> >
> > If it's not to be exported from Data.List (and I don't consider it
> > useful enough to be), maybe intersperseLoop wouldn't be too daft.
>
> I consider it useful, because the "natural" implementation:
>
>   prependToAll s = foldr (\ x r -> s : x : r) []
>
> seems to leak without optimization.

Another natural implementation would be

prependToAll s = (s :) . intersperse s

or, pointed,

prependToAll s xs = s : intersperse s xs

Those are of course a bit silly if intersperse is defined in terms of 
prependToAll.

But I don't see where one would need that function, so I'm hesitating to 
propose changing the API of Data.List. If you have use cases, I would 
probably support it.

>
> Cheers Christian
>
> > Cheers,
> > Daniel



More information about the Libraries mailing list