Names for small functions: just say no... Re: Data.List.join

Josef Svenningsson josef.svenningsson at
Mon Oct 30 08:03:23 EST 2006

On 10/29/06, Jon Fairbairn <jon.fairbairn at> wrote:
> On 2006-10-27 at 17:56+0200 "Josef Svenningsson" wrote:
> > My argument for intercalate builds on the fact that intersperse seems
> > to be the wrong abstraction. Recall that I supplied some evidence that
> > intersperse is only used together with concat:
> >
> Mostly, not only.
OK, it's mostly. If you had quoted a bit more of what I wrote I did
actually nuance my statement a bit, acknowledge pretty printing code
as an exception.

> > For me this suggests that intersperse is the wrong
> > abstraction. The right one is intercalate.
> I don't agree with the methodology... Firstly, while extant
> code tells you how things have been used, it doesn't tell
> you how they /should/ be used. Second, I suspect that the
> majority of current Haskell code was written by novices -- I
> don't mean anyone any disrespect, it's just that it takes
> quite a long time to become an expert, the number of new
> novices has been increasing rapidly and the people who have
> known Haskell long enough to be experts probably nolonger
> write so much code: they get their students to do it
> :-). [How many of the cases you found should have been foldr
> (.) id etc?]
Of course there is a risk of being influenced by bad coding principle
when using this methodology. But do you think that this is what
happened in this particular case? I challenge you to go through all
the search results and report any bad code that you find so that we
can avoid being influenced by that. I did that myself before sending
my proposal but given what you write above perhaps you should double

Then there is all the good code that *hasn't* been written but perhaps
should have been and therefore was excluded from the search. If you
feel that that's what happened here I ask you to put forward concrete
examples which we can learn from.

As for you second objection. To me it seems that because you don't
like the outcome of the code search you declare the programmers who
wrote the code to be immature.

> > I know that many people will argue that intersperse is
> > somehow more primitive or more natural than
> > intercalate.
> I don't know about natural. Looking back at the 25 year old
> Ponder list_ops library, I find that I defined
>   join_with filler l1 [] = l1
>   join_with filler l1 l2 = l1 ++ filler ++ l2
> and then
>   flatten_with filler = foldr (join_with filler) []
> which is another way of writing intercalate.

> > As for being more primitive, that's not true. Both
> > functions are interdefinable.
> Right. So your motive is more complicated than it appeared
> to me. I missed that first time round, sorry.
> The problem we have is that
>    intersperse x == intercalate [x] . map (:[])
> and
>    intercalate x = concat . intersperse x
> While it seems easier to me to work out the second than the
> first, I don't know if that is simply due to habituation. I
> can add that the second /looks/ simpler. So I /suspect/
> (unprovably) that were intercalate the preferred form,
> people would write intersperse in several different ways, in
> contrast to the present state of affairs where "concat
> . intersperse splod" seems already to have become idiomatic.
I agree that the second looks simpler.

So you're suspecting that people would define their own intersperse in
many different ways. I don't see how that fits in our current
discussion. No one is proposing to remove intersperse. If people do
find a need for intersperse then they should go ahead and use it. My
argument is that people *don't* use intersperse, at least not without
concat, and that that idiom will hopefully be replaced with

>  What would convince me of your case would be someone saying
> that intercalate is the <oojit> of the <weeble> category
> while intersperse enjoys no such property...
Yes. That would indeed be a nice thing. I know that the reasoning I
use to argue for intercalate is one which we are not used to in the
Haskell community. We want our stuff to be firmly based in mathematics
and not some accidental choice of idiom by some unknown body of
programmers. But I personally find intercalate very useful and common
enough to warrant a name. And apparently so does many others.

> ... or maybe I was right back then, and the natural
> primitive is something like join_with -- an operation to use
> with foldr?
Perhaps? But what does it mean to be right in this situation?

I'd like to come to some sort of conclusion. Judging from the response
I got from my suggestion to include intercalate in the library it
seems there is a clear majority in favour. And then there is you and a
few others who disagree. With the new submission guidelines we should
strive for a consensus about patches. How do you suggest we proceed?

And I didn't make this any easier by unilaterally applying the patch
before we had a consensus. But that patch is not the final word. There
is still time to make things right.

All the best,

Josef Svenningsson

More information about the Libraries mailing list