Proposal: Add cons function to Data.List module

Helmut Schmidt at
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

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

## Proposal


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

to Data.List
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list