Proposal: Add singleton function to Data.List module

Taylor Fausak taylor at
Mon Aug 12 16:14:37 UTC 2019

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


# 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:

## Proposal

I would like to add a `singleton` function to `Data.List` that mirrors the `singleton` function for other containers:

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

Other Haskell-like languages include this function:

- PureScript:
- Elm:

More information about the Libraries mailing list