Proposal: Add singleton function to Data.List module

Sven Panne svenpanne at gmail.com
Wed Aug 14 19:36:37 UTC 2019


Am Mi., 14. Aug. 2019 um 19:37 Uhr schrieb Matt <parsonsmatt at gmail.com>:

> There have been 19 votes cast so far. We have twelve +1 votes.
>

-1 from me, so we have 7 -1s now. >:-) BTW: Simply counting a tiny amount
of votes in a niche mailing list is not the best way to design APIs IMHO.


> Of the -1 votes, three are because "`pure` is fine" and four are because
> "`(:[])` is fine." I summarized the issue with `pure` in my previous email,
> and there hasn't been any response or comment on the issues raised.
>

I still fail to see the issues with "pure". Let's be honest: If somebody
has problems with polymorphic functions or operator sections, he will have
a hard time with Haskell in general. These are fundamental things in your
toolbox, and instead of coming up with tons of names which nobody can
remember (Fairbairn threshold, anyone?) for trivial things, time is better
spent educating people. Compared to the stuff you currently see in most
modern libraries (GADTs, lenses, type-level computations, ...)
understanding "pure" or "(: [])" will be your least problem.


> To summarize/quote the issues with `(:[])`:
>
> > You can't even search for it on hoogle:
> https://hoogle.haskell.org/?hoogle=(%3A%5B%5D)
> > Another advantage to having an explicit singleton function is
> discoverablity.
>
> The discoverability of `(:[])` is bad.
>

Why should I need to discover it when I can write it with 6 keystrokes (or
even 4)? Or as "\x -> [x]", which is basically a matter of taste?


> > Is `(:[])` a core idiom? I never see it in work code and I've never seen
> it in Hackage. To check, I grepped my software directory which has all my
> Haskell code, and got 122 matches of (:[]) over 1,768,231 loc (as given by
> wc -l **/*.hs).
>
> `(:[])` is not a common idiom (in the code sample I have; your mileage may
> vary).
>

It is quite obvious to me why you don't find it much in code. You have lots
of other ways to express the same thing:

   * You'll probably just use "[x]" if the argument already has a name.

   * If the argument doesn't have a name, you can give it one via "\x ->
[x]" (which I consider "explicit", not "noisy") or perhaps via eta
abstraction.

   * The code is intended to be polymorphic => "pure" is used.

   * Even if it's intended to be used monomorphic, there are often type
signatures around to make "pure" monomorphic enough.

This doesn't leave many sensible places. Perhaps as an argument for a
function, with very few type signatures around? Not a very convincing use
case IMHO.

In a nutshell: Just like Herbert, I can't see the problem we're trying to
solve. I would go even further: I would like to see a much more general
Prelude/base library, not a more monomorphic one. Pages like
https://haskell.fpcomplete.com/tutorial/synonyms cause quite a few "WTF?"
moments caused by the (nowadays) useless synonyms...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20190814/a21df6dc/attachment.html>


More information about the Libraries mailing list