laziness of intersperse

Thomas Schilling nominolo at googlemail.com
Sun Aug 17 05:00:52 EDT 2008


On Sun, Aug 17, 2008 at 9:43 AM, Barton C Massey <bart at cs.pdx.edu> wrote:
>  Maybe something like
>
>    intersperse _ [] = []
>    intersperse sep (x : xs) =
>        x : concatMap ((sep :) . (: [])) xs
>
> is clearer (maybe), but I doubt it's as efficient (although
> I haven't checked).

concatMap is a bit tricky when it comes to performance.  I also think
the low-level loop implementation that duncan showed is rather
readable.

> Thanks much for the corrections!  (I hope it's OK to do this on-list.)

Of course.  Nobody gets it right the first time.  (Well, maybe Oleg.
But then again we have some doubts whether he is from this planet or,
if he is, perhaps from the future.)


More information about the Libraries mailing list