Proposal: Add cons function to Data.List module

Helmut Schmidt helmut.schmidt.4711 at gmail.com
Wed Sep 11 06:36:24 UTC 2019


For more or less the same reasons that "singleton" was considered worth
being added to Data.List I propose to add "cons" to Data.List as well.

## Motivation

Sometimes it is convenient to have a function to prepend an element to a
list in pointless style code. But of the existing ways none of them are as
clear as a separate monomorphic function.

- "( : )" is subjectively ugly
- "(\x xs -> x : xs)" is syntactically noisy

Purescript also has a "Cons" function so why can't we have one too?

We already have "Data.List.uncons" and so for symmetry one would also
expect to find "Data.List.cons".

Many sequence like APIs have a "cons" function such as

https://www.stackage.org/haddock/nightly-2019-09-11/vector-0.12.0.3/Data-Vector.html#v:cons

I can't be the only that wants this function, right?

## Proposal

Add

cons :: x -> [x] -> [x]
cons = (:)

to Data.List
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20190911/7bde30c9/attachment.html>


More information about the Libraries mailing list