Proposal: Add singleton function to Data.List module

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
79 messages Options
1234
Reply | Threaded
Open this post in threaded view
|

Proposal: Add singleton function to Data.List module

Taylor Fausak
I originally made this suggestion on GitLab, but I was told to make it here instead.

https://gitlab.haskell.org/ghc/ghc/issues/17042

---

# Add list singleton function

## Motivation

Sometimes it is convenient to have a function to wrap an element in a list. There are many ways to do this already, but none of them are as clear as a separate monomorphic function.

- `pure`: Polymorphic, works for any `Functor`.
- `pure @[]`: Noisy, requires `-XTypeApplications`.
- `(: [])`: Subjectively ugly.
- `(\x -> [x])`: Syntactically noisy.

This Twitter thread includes some additional commentary: https://twitter.com/taylorfausak/status/1159264862247280640

## Proposal

I would like to add a `singleton` function to `Data.List` that mirrors the `singleton` function for other containers: https://www.stackage.org/lts-14.0/hoogle?q=singleton

``` hs
singleton :: a -> [a]
singleton x = [x]
```

Other Haskell-like languages include this function:

- PureScript: https://pursuit.purescript.org/packages/purescript-lists/5.4.0/docs/Data.List#v:singleton
- Elm: https://package.elm-lang.org/packages/elm/core/latest/List#singleton
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Oliver Charles-3
+1. All alternatives to construct a list "anonymously" are confusing
and take time to parse. An explicit `Data.List.singleton x` is very
clear what's going on.

On Mon, Aug 12, 2019 at 5:14 PM Taylor Fausak <[hidden email]> wrote:

>
> I originally made this suggestion on GitLab, but I was told to make it here instead.
>
> https://gitlab.haskell.org/ghc/ghc/issues/17042
>
> ---
>
> # Add list singleton function
>
> ## Motivation
>
> Sometimes it is convenient to have a function to wrap an element in a list. There are many ways to do this already, but none of them are as clear as a separate monomorphic function.
>
> - `pure`: Polymorphic, works for any `Functor`.
> - `pure @[]`: Noisy, requires `-XTypeApplications`.
> - `(: [])`: Subjectively ugly.
> - `(\x -> [x])`: Syntactically noisy.
>
> This Twitter thread includes some additional commentary: https://twitter.com/taylorfausak/status/1159264862247280640
>
> ## Proposal
>
> I would like to add a `singleton` function to `Data.List` that mirrors the `singleton` function for other containers: https://www.stackage.org/lts-14.0/hoogle?q=singleton
>
> ``` hs
> singleton :: a -> [a]
> singleton x = [x]
> ```
>
> Other Haskell-like languages include this function:
>
> - PureScript: https://pursuit.purescript.org/packages/purescript-lists/5.4.0/docs/Data.List#v:singleton
> - Elm: https://package.elm-lang.org/packages/elm/core/latest/List#singleton
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Herbert Valerio Riedel-3
In reply to this post by Taylor Fausak
> - `(:[])`: Subjectively ugly.

I consider "subjectively ugly" to be a non-technical and thus really
weak argument to dismiss the list-idiomatic ninja-robot-operator (:[])
which also happens to be shorter than the proposed alias for it. I for
one don't see a significant benefit for adding a redundant synonym to
`Data.List` and are thus -1 on this.

> singleton :: a -> [a]
> singleton x = [x]
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Oliver Charles-3
On Mon, Aug 12, 2019 at 6:03 PM Herbert Valerio Riedel
<[hidden email]> wrote:
>
> > - `(:[])`: Subjectively ugly.
>
> I consider "subjectively ugly" to be a non-technical and thus really
> weak argument to dismiss the list-idiomatic ninja-robot-operator (:[])
> which also happens to be shorter than the proposed alias for it. I for
> one don't see a significant benefit for adding a redundant synonym to
> `Data.List` and are thus -1 on this.

You are of course entitled to see this as a weak argument, but those
of us who are writing Haskell for 8 hours a day do not make all of our
decisions based on purely "technical" arguments. How easy it is for
myself and colleagues to review code is significant.

On the other hand, "the existing alternative happens to be shorter"
*is* a weak argument to me. There is no tax on characters typed, and
IMO we should be evaluating this change on whether or not it
contributes to code clarity, rather than "is long to type". Unless you
consider "singleton" to be so long it further obscures code, but I
have a hard time buying that.

Ollie
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

M Farkas-Dyck
In reply to this post by Taylor Fausak
-1, not worth increasing the size of base as `pure` works perfectly well
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Matt
In reply to this post by Oliver Charles-3
I'm +1 on this.

It's nice to have a relatively consistent naming scheme between container-types - `Data.Set` and `Data.Map` sharing mostly the same API names is really helpful for writing code without having to look up the specifics.  The `(:[])` operator takes me a decent amount longer to parse and recognize, and I have seen intermediate-level Haskellers trip up over unspaced operators like this in several contexts. Container-specific functions can be really useful to fix an ambiguous type in a long sequence of constrained polymorphic functions (like `length "hello"` becoming ambiguous with `OverloadedStrings`), and I've written `pure @[]` before to provide this disambiguation.

As far as I can tell, it's consistent, convenient, useful, and obvious. This IMO makes it a good candidate for inclusion.

Matt Parsons


On Mon, Aug 12, 2019 at 11:10 AM Oliver Charles <[hidden email]> wrote:
On Mon, Aug 12, 2019 at 6:03 PM Herbert Valerio Riedel
<[hidden email]> wrote:
>
> > - `(:[])`: Subjectively ugly.
>
> I consider "subjectively ugly" to be a non-technical and thus really
> weak argument to dismiss the list-idiomatic ninja-robot-operator (:[])
> which also happens to be shorter than the proposed alias for it. I for
> one don't see a significant benefit for adding a redundant synonym to
> `Data.List` and are thus -1 on this.

You are of course entitled to see this as a weak argument, but those
of us who are writing Haskell for 8 hours a day do not make all of our
decisions based on purely "technical" arguments. How easy it is for
myself and colleagues to review code is significant.

On the other hand, "the existing alternative happens to be shorter"
*is* a weak argument to me. There is no tax on characters typed, and
IMO we should be evaluating this change on whether or not it
contributes to code clarity, rather than "is long to type". Unless you
consider "singleton" to be so long it further obscures code, but I
have a hard time buying that.

Ollie
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Oliver Charles-3
In reply to this post by Oliver Charles-3
On Mon, Aug 12, 2019 at 6:10 PM Oliver Charles <[hidden email]> wrote:

> You are of course entitled to see this as a weak argument, but those
> of us who are writing Haskell for 8 hours a day do not make all of our
> decisions based on purely "technical" arguments. How easy it is for
> myself and colleagues to review code is significant.

Apologies, I see now this statement reads like 'I write more code that
hvr, so his opinion is worth less'. That wasn't my intention, in fact
I wasn't trying to provide any type of judgement as to how much hvr
writes (as I understand it, hvr writes plenty!). I was just trying to
emphasize how much this proposal means to me as a full time Haskell
programmer.

Seeing as I'm already derailing the conversation I'll step out of this
for now. Turns out I'm weirdly passionate about this single
expression!
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Zemyla
In reply to this post by Herbert Valerio Riedel-3
I also like the ninja-robot operator, because it's visually
interesting and easy to search for.

Also, if you're importing several libraries which already use
"singleton", then you have to use "List.singleton" every time, which
is far uglier to me.

On Mon, Aug 12, 2019 at 12:03 PM Herbert Valerio Riedel
<[hidden email]> wrote:

>
> > - `(:[])`: Subjectively ugly.
>
> I consider "subjectively ugly" to be a non-technical and thus really
> weak argument to dismiss the list-idiomatic ninja-robot-operator (:[])
> which also happens to be shorter than the proposed alias for it. I for
> one don't see a significant benefit for adding a redundant synonym to
> `Data.List` and are thus -1 on this.
>
> > singleton :: a -> [a]
> > singleton x = [x]
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Brent Yorgey
At the risk of completely derailing the conversation, I have always called this the "robot monkey operator".  I fail to see what is so ninja-like about it.

Anyway, I think I am +1 on adding Data.List.singleton.

-Brent

On Mon, Aug 12, 2019, 12:35 PM Zemyla <[hidden email]> wrote:
I also like the ninja-robot operator, because it's visually
interesting and easy to search for.

Also, if you're importing several libraries which already use
"singleton", then you have to use "List.singleton" every time, which
is far uglier to me.

On Mon, Aug 12, 2019 at 12:03 PM Herbert Valerio Riedel
<[hidden email]> wrote:
>
> > - `(:[])`: Subjectively ugly.
>
> I consider "subjectively ugly" to be a non-technical and thus really
> weak argument to dismiss the list-idiomatic ninja-robot-operator (:[])
> which also happens to be shorter than the proposed alias for it. I for
> one don't see a significant benefit for adding a redundant synonym to
> `Data.List` and are thus -1 on this.
>
> > singleton :: a -> [a]
> > singleton x = [x]
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Andrew Lelechenko
- `pure`: Polymorphic, works for any `Functor`.

It is OK to have polymorphic folds and length, so what is wrong with pure? 

Adding singleton to Data.List is a breaking change, when Data.Map.singleton was exported unqualified. 
And there is no singleton in Data.List.NonEmpty as well. 

-1 from me.

Best regards,
Andrew

On 12 Aug 2019, at 19:36, Brent Yorgey <[hidden email]> wrote:

At the risk of completely derailing the conversation, I have always called this the "robot monkey operator".  I fail to see what is so ninja-like about it.

Anyway, I think I am +1 on adding Data.List.singleton.

-Brent

On Mon, Aug 12, 2019, 12:35 PM Zemyla <[hidden email]> wrote:
I also like the ninja-robot operator, because it's visually
interesting and easy to search for.

Also, if you're importing several libraries which already use
"singleton", then you have to use "List.singleton" every time, which
is far uglier to me.

On Mon, Aug 12, 2019 at 12:03 PM Herbert Valerio Riedel
<[hidden email]> wrote:
>
> > - `(:[])`: Subjectively ugly.
>
> I consider "subjectively ugly" to be a non-technical and thus really
> weak argument to dismiss the list-idiomatic ninja-robot-operator (:[])
> which also happens to be shorter than the proposed alias for it. I for
> one don't see a significant benefit for adding a redundant synonym to
> `Data.List` and are thus -1 on this.
>
> > singleton :: a -> [a]
> > singleton x = [x]
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Andreas Abel
In reply to this post by Brent Yorgey
In the Agda code base there is a overloaded version of the singleton
function.  Even more useful in its overloaded form!

   https://github.com/agda/agda/blob/master/src/full/Agda/Utils/Singleton.hs

As you can see here, singleton exists for many collection types already,
it makes very much sense to have it also for List (and List.Nonempty).

+1 on Data.List.singleton, (but please not in the Prelude).

On 2019-08-12 20:36, Brent Yorgey wrote:

> At the risk of completely derailing the conversation, I have always
> called this the "robot monkey operator".  I fail to see what is so
> ninja-like about it.
>
> Anyway, I think I am +1 on adding Data.List.singleton.
>
> -Brent
>
> On Mon, Aug 12, 2019, 12:35 PM Zemyla <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     I also like the ninja-robot operator, because it's visually
>     interesting and easy to search for.
>
>     Also, if you're importing several libraries which already use
>     "singleton", then you have to use "List.singleton" every time, which
>     is far uglier to me.
>
>     On Mon, Aug 12, 2019 at 12:03 PM Herbert Valerio Riedel
>     <[hidden email] <mailto:[hidden email]>> wrote:
>      >
>      > > - `(:[])`: Subjectively ugly.
>      >
>      > I consider "subjectively ugly" to be a non-technical and thus really
>      > weak argument to dismiss the list-idiomatic ninja-robot-operator
>     (:[])
>      > which also happens to be shorter than the proposed alias for it.
>     I for
>      > one don't see a significant benefit for adding a redundant synonym to
>      > `Data.List` and are thus -1 on this.
>      >
>      > > singleton :: a -> [a]
>      > > singleton x = [x]
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Taylor Fausak
In reply to this post by Taylor Fausak
Coincidentally a related discussion came up on Reddit this morning:

https://np.reddit.com/r/haskell/comments/cpdlbr/how_would_i_go_about_printing_every_syllable/ewoplka/?context=1

On Mon, Aug 12, 2019, at 12:14 PM, Taylor Fausak wrote:

> I originally made this suggestion on GitLab, but I was told to make it
> here instead.
>
> https://gitlab.haskell.org/ghc/ghc/issues/17042
>
> ---
>
> # Add list singleton function
>
> ## Motivation
>
> Sometimes it is convenient to have a function to wrap an element in a
> list. There are many ways to do this already, but none of them are as
> clear as a separate monomorphic function.
>
> - `pure`: Polymorphic, works for any `Functor`.
> - `pure @[]`: Noisy, requires `-XTypeApplications`.
> - `(: [])`: Subjectively ugly.
> - `(\x -> [x])`: Syntactically noisy.
>
> This Twitter thread includes some additional commentary:
> https://twitter.com/taylorfausak/status/1159264862247280640
>
> ## Proposal
>
> I would like to add a `singleton` function to `Data.List` that mirrors
> the `singleton` function for other containers:
> https://www.stackage.org/lts-14.0/hoogle?q=singleton
>
> ``` hs
> singleton :: a -> [a]
> singleton x = [x]
> ```
>
> Other Haskell-like languages include this function:
>
> - PureScript:
> https://pursuit.purescript.org/packages/purescript-lists/5.4.0/docs/Data.List#v:singleton
> - Elm:
> https://package.elm-lang.org/packages/elm/core/latest/List#singleton
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Theodore Lief Gannon
In reply to this post by Andrew Lelechenko
On Mon, Aug 12, 2019, 12:53 PM Andrew Lelechenko <[hidden email]> wrote:
Adding singleton to Data.List is a breaking change, when Data.Map.singleton was exported unqualified. 

Data.Map's documentation states that the entire module should be imported qualified; this is not a reasonable counterargument.

RIO even takes the potentially-conflicting List functions out of Prelude, and puts them in a RIO.List module which is also intended for qualified import.

I'm +1. Personally I prefer `pure` and have TypeApplication enabled globally; but that's not a universal style, and I see no real cost here (though I agree it shouldn't be exposed in Prelude).

NonEmpty should get one too.

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Elliot Cameron-2
+1 and for NonEmpty. It's a common pattern for containers and I've always been annoyed that List did not go with the flow.

On Mon, Aug 12, 2019 at 6:36 PM Theodore Lief Gannon <[hidden email]> wrote:
On Mon, Aug 12, 2019, 12:53 PM Andrew Lelechenko <[hidden email]> wrote:
Adding singleton to Data.List is a breaking change, when Data.Map.singleton was exported unqualified. 

Data.Map's documentation states that the entire module should be imported qualified; this is not a reasonable counterargument.

RIO even takes the potentially-conflicting List functions out of Prelude, and puts them in a RIO.List module which is also intended for qualified import.

I'm +1. Personally I prefer `pure` and have TypeApplication enabled globally; but that's not a universal style, and I see no real cost here (though I agree it shouldn't be exposed in Prelude).

NonEmpty should get one too.
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Joseph C. Sible
In reply to this post by Taylor Fausak
-1. AFAICT, "Polymorphic, works for any `Functor`" is an upside of
just using `pure`, not a downside. (Please correct me if I'm wrong,
and there is some disadvantage that I don't see.) Also, it looks like
for everything that has a `singleton`, it's something that isn't an
applicative functor, so they have them instead of `pure`, not in
addition to it.

Joseph C. Sible

On Mon, Aug 12, 2019 at 12:14 PM Taylor Fausak <[hidden email]> wrote:

>
> I originally made this suggestion on GitLab, but I was told to make it here instead.
>
> https://gitlab.haskell.org/ghc/ghc/issues/17042
>
> ---
>
> # Add list singleton function
>
> ## Motivation
>
> Sometimes it is convenient to have a function to wrap an element in a list. There are many ways to do this already, but none of them are as clear as a separate monomorphic function.
>
> - `pure`: Polymorphic, works for any `Functor`.
> - `pure @[]`: Noisy, requires `-XTypeApplications`.
> - `(: [])`: Subjectively ugly.
> - `(\x -> [x])`: Syntactically noisy.
>
> This Twitter thread includes some additional commentary: https://twitter.com/taylorfausak/status/1159264862247280640
>
> ## Proposal
>
> I would like to add a `singleton` function to `Data.List` that mirrors the `singleton` function for other containers: https://www.stackage.org/lts-14.0/hoogle?q=singleton
>
> ``` hs
> singleton :: a -> [a]
> singleton x = [x]
> ```
>
> Other Haskell-like languages include this function:
>
> - PureScript: https://pursuit.purescript.org/packages/purescript-lists/5.4.0/docs/Data.List#v:singleton
> - Elm: https://package.elm-lang.org/packages/elm/core/latest/List#singleton
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

George Wilson
Weak +1, I'd want it in NonEmpty too if it's going into List.

On Tue, 13 Aug 2019 at 13:37, Joseph C. Sible <[hidden email]> wrote:

>
> -1. AFAICT, "Polymorphic, works for any `Functor`" is an upside of
> just using `pure`, not a downside. (Please correct me if I'm wrong,
> and there is some disadvantage that I don't see.) Also, it looks like
> for everything that has a `singleton`, it's something that isn't an
> applicative functor, so they have them instead of `pure`, not in
> addition to it.
>
> Joseph C. Sible
>
> On Mon, Aug 12, 2019 at 12:14 PM Taylor Fausak <[hidden email]> wrote:
> >
> > I originally made this suggestion on GitLab, but I was told to make it here instead.
> >
> > https://gitlab.haskell.org/ghc/ghc/issues/17042
> >
> > ---
> >
> > # Add list singleton function
> >
> > ## Motivation
> >
> > Sometimes it is convenient to have a function to wrap an element in a list. There are many ways to do this already, but none of them are as clear as a separate monomorphic function.
> >
> > - `pure`: Polymorphic, works for any `Functor`.
> > - `pure @[]`: Noisy, requires `-XTypeApplications`.
> > - `(: [])`: Subjectively ugly.
> > - `(\x -> [x])`: Syntactically noisy.
> >
> > This Twitter thread includes some additional commentary: https://twitter.com/taylorfausak/status/1159264862247280640
> >
> > ## Proposal
> >
> > I would like to add a `singleton` function to `Data.List` that mirrors the `singleton` function for other containers: https://www.stackage.org/lts-14.0/hoogle?q=singleton
> >
> > ``` hs
> > singleton :: a -> [a]
> > singleton x = [x]
> > ```
> >
> > Other Haskell-like languages include this function:
> >
> > - PureScript: https://pursuit.purescript.org/packages/purescript-lists/5.4.0/docs/Data.List#v:singleton
> > - Elm: https://package.elm-lang.org/packages/elm/core/latest/List#singleton
> > _______________________________________________
> > Libraries mailing list
> > [hidden email]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Elliot Cameron-2
Seq is applicative and also has singleton. Some people like to avoid polymorphism when the use case is clearly monomorphic (c.f. discussion about map vs fmap).

I'd like to point out that Pointed is sort of the abstraction we really want for this... But I still want a monomorphic function that doesn't delve into Kmett dependencies.

On Mon, Aug 12, 2019 at 11:59 PM George Wilson <[hidden email]> wrote:
Weak +1, I'd want it in NonEmpty too if it's going into List.

On Tue, 13 Aug 2019 at 13:37, Joseph C. Sible <[hidden email]> wrote:
>
> -1. AFAICT, "Polymorphic, works for any `Functor`" is an upside of
> just using `pure`, not a downside. (Please correct me if I'm wrong,
> and there is some disadvantage that I don't see.) Also, it looks like
> for everything that has a `singleton`, it's something that isn't an
> applicative functor, so they have them instead of `pure`, not in
> addition to it.
>
> Joseph C. Sible
>
> On Mon, Aug 12, 2019 at 12:14 PM Taylor Fausak <[hidden email]> wrote:
> >
> > I originally made this suggestion on GitLab, but I was told to make it here instead.
> >
> > https://gitlab.haskell.org/ghc/ghc/issues/17042
> >
> > ---
> >
> > # Add list singleton function
> >
> > ## Motivation
> >
> > Sometimes it is convenient to have a function to wrap an element in a list. There are many ways to do this already, but none of them are as clear as a separate monomorphic function.
> >
> > - `pure`: Polymorphic, works for any `Functor`.
> > - `pure @[]`: Noisy, requires `-XTypeApplications`.
> > - `(: [])`: Subjectively ugly.
> > - `(\x -> [x])`: Syntactically noisy.
> >
> > This Twitter thread includes some additional commentary: https://twitter.com/taylorfausak/status/1159264862247280640
> >
> > ## Proposal
> >
> > I would like to add a `singleton` function to `Data.List` that mirrors the `singleton` function for other containers: https://www.stackage.org/lts-14.0/hoogle?q=singleton
> >
> > ``` hs
> > singleton :: a -> [a]
> > singleton x = [x]
> > ```
> >
> > Other Haskell-like languages include this function:
> >
> > - PureScript: https://pursuit.purescript.org/packages/purescript-lists/5.4.0/docs/Data.List#v:singleton
> > - Elm: https://package.elm-lang.org/packages/elm/core/latest/List#singleton
> > _______________________________________________
> > Libraries mailing list
> > [hidden email]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Matthew Pickering
Clear +1 from me. I have defined this function many times.

The addition of a one line function does not prevent anyone from using
`pure` in their own code if they wish to obfuscate matters.

Cheers,

Matt

On Tue, Aug 13, 2019 at 6:35 AM Elliot Cameron <[hidden email]> wrote:

>
> Seq is applicative and also has singleton. Some people like to avoid polymorphism when the use case is clearly monomorphic (c.f. discussion about map vs fmap).
>
> I'd like to point out that Pointed is sort of the abstraction we really want for this... But I still want a monomorphic function that doesn't delve into Kmett dependencies.
>
> On Mon, Aug 12, 2019 at 11:59 PM George Wilson <[hidden email]> wrote:
>>
>> Weak +1, I'd want it in NonEmpty too if it's going into List.
>>
>> On Tue, 13 Aug 2019 at 13:37, Joseph C. Sible <[hidden email]> wrote:
>> >
>> > -1. AFAICT, "Polymorphic, works for any `Functor`" is an upside of
>> > just using `pure`, not a downside. (Please correct me if I'm wrong,
>> > and there is some disadvantage that I don't see.) Also, it looks like
>> > for everything that has a `singleton`, it's something that isn't an
>> > applicative functor, so they have them instead of `pure`, not in
>> > addition to it.
>> >
>> > Joseph C. Sible
>> >
>> > On Mon, Aug 12, 2019 at 12:14 PM Taylor Fausak <[hidden email]> wrote:
>> > >
>> > > I originally made this suggestion on GitLab, but I was told to make it here instead.
>> > >
>> > > https://gitlab.haskell.org/ghc/ghc/issues/17042
>> > >
>> > > ---
>> > >
>> > > # Add list singleton function
>> > >
>> > > ## Motivation
>> > >
>> > > Sometimes it is convenient to have a function to wrap an element in a list. There are many ways to do this already, but none of them are as clear as a separate monomorphic function.
>> > >
>> > > - `pure`: Polymorphic, works for any `Functor`.
>> > > - `pure @[]`: Noisy, requires `-XTypeApplications`.
>> > > - `(: [])`: Subjectively ugly.
>> > > - `(\x -> [x])`: Syntactically noisy.
>> > >
>> > > This Twitter thread includes some additional commentary: https://twitter.com/taylorfausak/status/1159264862247280640
>> > >
>> > > ## Proposal
>> > >
>> > > I would like to add a `singleton` function to `Data.List` that mirrors the `singleton` function for other containers: https://www.stackage.org/lts-14.0/hoogle?q=singleton
>> > >
>> > > ``` hs
>> > > singleton :: a -> [a]
>> > > singleton x = [x]
>> > > ```
>> > >
>> > > Other Haskell-like languages include this function:
>> > >
>> > > - PureScript: https://pursuit.purescript.org/packages/purescript-lists/5.4.0/docs/Data.List#v:singleton
>> > > - Elm: https://package.elm-lang.org/packages/elm/core/latest/List#singleton
>> > > _______________________________________________
>> > > Libraries mailing list
>> > > [hidden email]
>> > > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>> > _______________________________________________
>> > Libraries mailing list
>> > [hidden email]
>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>> _______________________________________________
>> Libraries mailing list
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Edward Kmett-2
I'm a very weak personal -1 on this, just because pure already exists, is half the length of the word in question, and adding 'singleton' will introduce at least a few import conflicts, but I won't fight too hard for my position.

-Edward

On Tue, Aug 13, 2019 at 12:44 AM Matthew Pickering <[hidden email]> wrote:
Clear +1 from me. I have defined this function many times.

The addition of a one line function does not prevent anyone from using
`pure` in their own code if they wish to obfuscate matters.

Cheers,

Matt

On Tue, Aug 13, 2019 at 6:35 AM Elliot Cameron <[hidden email]> wrote:
>
> Seq is applicative and also has singleton. Some people like to avoid polymorphism when the use case is clearly monomorphic (c.f. discussion about map vs fmap).
>
> I'd like to point out that Pointed is sort of the abstraction we really want for this... But I still want a monomorphic function that doesn't delve into Kmett dependencies.
>
> On Mon, Aug 12, 2019 at 11:59 PM George Wilson <[hidden email]> wrote:
>>
>> Weak +1, I'd want it in NonEmpty too if it's going into List.
>>
>> On Tue, 13 Aug 2019 at 13:37, Joseph C. Sible <[hidden email]> wrote:
>> >
>> > -1. AFAICT, "Polymorphic, works for any `Functor`" is an upside of
>> > just using `pure`, not a downside. (Please correct me if I'm wrong,
>> > and there is some disadvantage that I don't see.) Also, it looks like
>> > for everything that has a `singleton`, it's something that isn't an
>> > applicative functor, so they have them instead of `pure`, not in
>> > addition to it.
>> >
>> > Joseph C. Sible
>> >
>> > On Mon, Aug 12, 2019 at 12:14 PM Taylor Fausak <[hidden email]> wrote:
>> > >
>> > > I originally made this suggestion on GitLab, but I was told to make it here instead.
>> > >
>> > > https://gitlab.haskell.org/ghc/ghc/issues/17042
>> > >
>> > > ---
>> > >
>> > > # Add list singleton function
>> > >
>> > > ## Motivation
>> > >
>> > > Sometimes it is convenient to have a function to wrap an element in a list. There are many ways to do this already, but none of them are as clear as a separate monomorphic function.
>> > >
>> > > - `pure`: Polymorphic, works for any `Functor`.
>> > > - `pure @[]`: Noisy, requires `-XTypeApplications`.
>> > > - `(: [])`: Subjectively ugly.
>> > > - `(\x -> [x])`: Syntactically noisy.
>> > >
>> > > This Twitter thread includes some additional commentary: https://twitter.com/taylorfausak/status/1159264862247280640
>> > >
>> > > ## Proposal
>> > >
>> > > I would like to add a `singleton` function to `Data.List` that mirrors the `singleton` function for other containers: https://www.stackage.org/lts-14.0/hoogle?q=singleton
>> > >
>> > > ``` hs
>> > > singleton :: a -> [a]
>> > > singleton x = [x]
>> > > ```
>> > >
>> > > Other Haskell-like languages include this function:
>> > >
>> > > - PureScript: https://pursuit.purescript.org/packages/purescript-lists/5.4.0/docs/Data.List#v:singleton
>> > > - Elm: https://package.elm-lang.org/packages/elm/core/latest/List#singleton
>> > > _______________________________________________
>> > > Libraries mailing list
>> > > [hidden email]
>> > > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>> > _______________________________________________
>> > Libraries mailing list
>> > [hidden email]
>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>> _______________________________________________
>> Libraries mailing list
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add singleton function to Data.List module

Tikhon Jelvis
In reply to this post by Matthew Pickering
Another advantage to having an explicit singleton function is discoverablity. I distinctly remember looking for exactly this function when I was a beginner and being confused because it didn't seem to exist.

Idioms like (:[]) are not intuitive at all. Polymorphic functions like pure require you to know that list is an Applicative, which you won't learn right away. Even if your have learned about Applicatives, it's easy to miss that connection when you're thinking about lists as a data structure rather than as a control structure, which is exactly the scenario I expect people to use a singleton function.

On Tue, Aug 13, 2019, 09:44 Matthew Pickering <[hidden email]> wrote:
Clear +1 from me. I have defined this function many times.

The addition of a one line function does not prevent anyone from using
`pure` in their own code if they wish to obfuscate matters.

Cheers,

Matt

On Tue, Aug 13, 2019 at 6:35 AM Elliot Cameron <[hidden email]> wrote:
>
> Seq is applicative and also has singleton. Some people like to avoid polymorphism when the use case is clearly monomorphic (c.f. discussion about map vs fmap).
>
> I'd like to point out that Pointed is sort of the abstraction we really want for this... But I still want a monomorphic function that doesn't delve into Kmett dependencies.
>
> On Mon, Aug 12, 2019 at 11:59 PM George Wilson <[hidden email]> wrote:
>>
>> Weak +1, I'd want it in NonEmpty too if it's going into List.
>>
>> On Tue, 13 Aug 2019 at 13:37, Joseph C. Sible <[hidden email]> wrote:
>> >
>> > -1. AFAICT, "Polymorphic, works for any `Functor`" is an upside of
>> > just using `pure`, not a downside. (Please correct me if I'm wrong,
>> > and there is some disadvantage that I don't see.) Also, it looks like
>> > for everything that has a `singleton`, it's something that isn't an
>> > applicative functor, so they have them instead of `pure`, not in
>> > addition to it.
>> >
>> > Joseph C. Sible
>> >
>> > On Mon, Aug 12, 2019 at 12:14 PM Taylor Fausak <[hidden email]> wrote:
>> > >
>> > > I originally made this suggestion on GitLab, but I was told to make it here instead.
>> > >
>> > > https://gitlab.haskell.org/ghc/ghc/issues/17042
>> > >
>> > > ---
>> > >
>> > > # Add list singleton function
>> > >
>> > > ## Motivation
>> > >
>> > > Sometimes it is convenient to have a function to wrap an element in a list. There are many ways to do this already, but none of them are as clear as a separate monomorphic function.
>> > >
>> > > - `pure`: Polymorphic, works for any `Functor`.
>> > > - `pure @[]`: Noisy, requires `-XTypeApplications`.
>> > > - `(: [])`: Subjectively ugly.
>> > > - `(\x -> [x])`: Syntactically noisy.
>> > >
>> > > This Twitter thread includes some additional commentary: https://twitter.com/taylorfausak/status/1159264862247280640
>> > >
>> > > ## Proposal
>> > >
>> > > I would like to add a `singleton` function to `Data.List` that mirrors the `singleton` function for other containers: https://www.stackage.org/lts-14.0/hoogle?q=singleton
>> > >
>> > > ``` hs
>> > > singleton :: a -> [a]
>> > > singleton x = [x]
>> > > ```
>> > >
>> > > Other Haskell-like languages include this function:
>> > >
>> > > - PureScript: https://pursuit.purescript.org/packages/purescript-lists/5.4.0/docs/Data.List#v:singleton
>> > > - Elm: https://package.elm-lang.org/packages/elm/core/latest/List#singleton
>> > > _______________________________________________
>> > > Libraries mailing list
>> > > [hidden email]
>> > > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>> > _______________________________________________
>> > Libraries mailing list
>> > [hidden email]
>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>> _______________________________________________
>> Libraries mailing list
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
1234