<div dir="auto">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.<div dir="auto"><br></div><div dir="auto">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.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 13, 2019, 09:44 Matthew Pickering <<a href="mailto:matthewtpickering@gmail.com">matthewtpickering@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Clear +1 from me. I have defined this function many times.<br>
<br>
The addition of a one line function does not prevent anyone from using<br>
`pure` in their own code if they wish to obfuscate matters.<br>
<br>
Cheers,<br>
<br>
Matt<br>
<br>
On Tue, Aug 13, 2019 at 6:35 AM Elliot Cameron <<a href="mailto:eacameron@gmail.com" target="_blank" rel="noreferrer">eacameron@gmail.com</a>> wrote:<br>
><br>
> 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).<br>
><br>
> 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.<br>
><br>
> On Mon, Aug 12, 2019 at 11:59 PM George Wilson <george@wils.online> wrote:<br>
>><br>
>> Weak +1, I'd want it in NonEmpty too if it's going into List.<br>
>><br>
>> On Tue, 13 Aug 2019 at 13:37, Joseph C. Sible <<a href="mailto:josephcsible@gmail.com" target="_blank" rel="noreferrer">josephcsible@gmail.com</a>> wrote:<br>
>> ><br>
>> > -1. AFAICT, "Polymorphic, works for any `Functor`" is an upside of<br>
>> > just using `pure`, not a downside. (Please correct me if I'm wrong,<br>
>> > and there is some disadvantage that I don't see.) Also, it looks like<br>
>> > for everything that has a `singleton`, it's something that isn't an<br>
>> > applicative functor, so they have them instead of `pure`, not in<br>
>> > addition to it.<br>
>> ><br>
>> > Joseph C. Sible<br>
>> ><br>
>> > On Mon, Aug 12, 2019 at 12:14 PM Taylor Fausak <<a href="mailto:taylor@fausak.me" target="_blank" rel="noreferrer">taylor@fausak.me</a>> wrote:<br>
>> > ><br>
>> > > I originally made this suggestion on GitLab, but I was told to make it here instead.<br>
>> > ><br>
>> > > <a href="https://gitlab.haskell.org/ghc/ghc/issues/17042" rel="noreferrer noreferrer" target="_blank">https://gitlab.haskell.org/ghc/ghc/issues/17042</a><br>
>> > ><br>
>> > > ---<br>
>> > ><br>
>> > > # Add list singleton function<br>
>> > ><br>
>> > > ## Motivation<br>
>> > ><br>
>> > > 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.<br>
>> > ><br>
>> > > - `pure`: Polymorphic, works for any `Functor`.<br>
>> > > - `pure @[]`: Noisy, requires `-XTypeApplications`.<br>
>> > > - `(: [])`: Subjectively ugly.<br>
>> > > - `(\x -> [x])`: Syntactically noisy.<br>
>> > ><br>
>> > > This Twitter thread includes some additional commentary: <a href="https://twitter.com/taylorfausak/status/1159264862247280640" rel="noreferrer noreferrer" target="_blank">https://twitter.com/taylorfausak/status/1159264862247280640</a><br>
>> > ><br>
>> > > ## Proposal<br>
>> > ><br>
>> > > I would like to add a `singleton` function to `Data.List` that mirrors the `singleton` function for other containers: <a href="https://www.stackage.org/lts-14.0/hoogle?q=singleton" rel="noreferrer noreferrer" target="_blank">https://www.stackage.org/lts-14.0/hoogle?q=singleton</a><br>
>> > ><br>
>> > > ``` hs<br>
>> > > singleton :: a -> [a]<br>
>> > > singleton x = [x]<br>
>> > > ```<br>
>> > ><br>
>> > > Other Haskell-like languages include this function:<br>
>> > ><br>
>> > > - PureScript: <a href="https://pursuit.purescript.org/packages/purescript-lists/5.4.0/docs/Data.List#v:singleton" rel="noreferrer noreferrer" target="_blank">https://pursuit.purescript.org/packages/purescript-lists/5.4.0/docs/Data.List#v:singleton</a><br>
>> > > - Elm: <a href="https://package.elm-lang.org/packages/elm/core/latest/List#singleton" rel="noreferrer noreferrer" target="_blank">https://package.elm-lang.org/packages/elm/core/latest/List#singleton</a><br>
>> > > _______________________________________________<br>
>> > > Libraries mailing list<br>
>> > > <a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
>> > > <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
>> > _______________________________________________<br>
>> > Libraries mailing list<br>
>> > <a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
>> > <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
>> _______________________________________________<br>
>> Libraries mailing list<br>
>> <a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
>> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
><br>
> _______________________________________________<br>
> Libraries mailing list<br>
> <a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>