Proposal: Add singleton function to Data.List module

Taylor Fausak taylor at fausak.me
Mon Aug 12 21:16:38 UTC 2019


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
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>


More information about the Libraries mailing list