Fellow committee members,
On 2019-08-20 at 11:33:01 +1000, George Wilson wrote:
[...]
> As you know, there is a trac ticket and an ongoing discussion on
> libraries@ regarding adding the following function to Data.List
>
> singleton :: a -> [a]
> singleton x = [x]
>
> The discussion has continued for a week with nearly 50 replies. No
> discussion period was given, but tensions are high and the discussion
> is spilling into twitter. We should come to an official decision
> sooner rather than later and put the issue to bed.
I don't like the concept of being pressued into a decision because
there's some Twitter mob out there trying to effect a certain
decision... if we decide the "wrong" way, that same Twitter mob will
certainly go away, right? ;-)
> The maintainers of base are Edward and Ryan, but this is a
> "controversial change" [1] because it requires changes to the Report
> [2], which specifies the Data.List module.
I feel like this should be emphasized more: This proposal is effectively
proposing to change the Haskell (Library) Report (and is also strongly
related to the overall language design of Haskell), and as such ought to
be justified by strong and compelling benefit.
And the proposal literally started out with the rationale of
> - `(: [])`: Subjectively ugly.
> - `(\x -> [x])`: Syntactically noisy.
If we start going down that road, you'll find that everyone has
different subjective perceptions. But since we're not designing a new
language, the best course of action IMO is to adhere to the design of
the language we have at our disposal; and in case of Haskell, the syntax
rules are designed in such a way that make (:[]) or (\x->[x]) an legit
construct.
IMO, Jon Fairbairn put it quite well,
,----
| > Idioms like (:[]) are not intuitive at all.
|
| Can you explain that? Once one knows that all infix operators
| can be used in sections (+1), (++"foo"), etc, that notation
| should be obvious, both in reading and writing. It’s much better
| to use ideas that are uniformly usable throughout the language
| and can be learned once than to have to learn numerous specific
| words.
`----
so IMO, `Data.List.singleton` doesn't really add much value and falls
short of some variant of the Fairbairn-threshold.
As you may know, I teach frequently students Haskell, and I frequently
do demonstration in GHCi, where stuff like (:[]) will easily slip in --
and it's a good thing, as then some student's curiosity about that
operator will be picked, et voila, I have a teachable moment to remind
everyone of the operator sections and variants such as (:"") or
((,)True), (True(,)), (:".exe") and so on...
David pointed out something similar:
,----
| Whilst taking the point, could I just pit out that, its not just about
| the form of the final program. One of the strengths and appeals of FP id
| the opportunity for program transformation via a useful repertoire of
| algebraic law, cf the work on Squiggol, and the numerous pearls by folk
| including Richard Bird
et.al.. This work befits from having
| concisely-expressed rules that open the road to manipulation -
| long-winded identifiers suitable for large libraries are not necessarily
| ideal here.
|
| Going back to the original proposal, I'm not bothered, I would probably
| just ignore a singleton library in favour of :[]. I'm -1 on
| philosophical grounds.
|
| I'm used to teaching FP to undergrads and half the battle is encouraging
| people to think functionally, to make use of the underlying mathematics
| and computational model rather than transliterate Python or <insert your
| favourite 'bete noir'> into Haskell. That means thinking of building
| programs from functional fragments combined by suitable glue, and
| appreciating that data constructors can be used as functions Yes takes
| beginner's time to recognise some of the patterns, but when the light
| dawns, the transformation is rewarding. I've lost count of the number of
| jaws I've had to pick off the floor :)
`----
(Sideremark: what if somebody proposes to add Data.String.singleton on
the grounds they need a monomorphic singleton variant `:: Char ->
String` cause (:"") may be considered "subjectively ugly")
Also, we shouldn't add something to a Haskell Report module which I feel
won't see much use anyway for various reasons; see e.g. how Sven put it:
,----
| 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...
`----
Moreover, in order to use it you'll have to `import Data.List` (assuming
you have a new enough `base`) at which point just reaching out for the
universal `(:[])` which is in principle available even without any names
imported, (i.e. `import Prelude ()`) will be what I argue most people
will just use (:[]) or (\x->[x]) in those rare occasions where you
really insist on using a list-specialised `::x->[x]`-type function.
So on the grounds that `Data.List.singleton` (by virtue of being a
redundant alias) doesn't add any technical benefit, lacks clear
consensus, seems inconvenient to use, is likely to end up being a
deadweight function only few people will use (if they even discover it),
it will likely not be mentioned (or at best be recommended against) by
FP teachers (like myself and David), it is a modification of the Haskell
Report which IMO doesn't carry its own weight (in fact, we should rather
try to remove redundancies in the Haskell Library Report than add even
more noise to it), I'm still strongly -1 on this.
`singleton` seems to be something more suited for one of the many
alternative preludes out there.
> Sentiment is net positive among non-CLC libraries@ members.
It's not a clear majority though, is it (it's currently somewhere
13-vs-16 on the libraries@ isn't it? i.e. flip two votes and we're
suddenly in a net-negative situation...)? As you pointed out, the
discussion got heated and is controversial; there certainly isn't any
clear consensus for this change.
And if there isn't a clear consensus that justifies and mandates a call
to action, shouldn't we rather leave the status quo as is than to push
some low-value purely cosmetic changes?