Announcing the list-singleton package

by Taylor Fausak on

Have you ever found yourself typing the five-character Haskell expression (:[]) and thinking to yourself, “I wish I could add an external dependency for this”? If so, great news! I published the list-singleton package today and it does just that.

Seriously though, I’m on a quest to add this singleton function to Data.List (and Data.List.NonEmpty):

singleton :: a -> [a]
singleton a = [a]

You’re probably thinking that there are plenty of ways to make singleton lists already. You’re right! However I think it would be useful to have a documented, monomorphic function for this exact use case. Check out the singleton documentation for a deep dive.

I submitted a proposal to the Core Libraries Committee nearly a month ago. Although it generated a fair amount of discussion, it doesn’t seem to me like the CLC is any closer to deciding on it.

That inaction made me grumpy, so I decided to create something rather than complain about it. Thus list-singleton was born! I don’t really expect anyone to depend on this library for one tiny function. I made it to show what the implementation and documentation could look like. Also it should show up when someone searches Hoogle for singleton or a -> [a], and then the documentation can point that person in the right direction.