Proposal: Add singleton function to Data.List module

Tikhon Jelvis tikhon at jelv.is
Tue Aug 13 09:10:26 UTC 2019


The reason it's particularly unintuitive for lists is that we almost never
explicitly construct lists using : and []. Sections like (+ 1) or (++
"Foo") reflect expressions like x + 1 and str ++ "Foo", but you simply
never see x : [] in the wild. (In fact, in code review, I would always
expect that to be rewritten as [x].)

In turn, this means that (:[]) doesn't convey my intentions as directly as
possible. I want to build a list that contains a single element x, which I
usually think of as [x]; the fact that I do this by consing x with an empty
list is an implementation detail.

More generally, lists merit a special case because list notation is
*already* a special case, and we can't do anything about that at this point!


On Tue, Aug 13, 2019, 10:49 Jon Fairbairn <jon.fairbairn at cl.cam.ac.uk>
wrote:

> Tikhon Jelvis <tikhon at jelv.is> writes:
>
> > 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.
>
> I’m -1 on the proposal, obviously.
>
> --
> Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20190813/440da477/attachment.html>


More information about the Libraries mailing list