Proposal: add 'equating' function to Data.List

David Feuer david.feuer at
Fri Jul 18 21:19:11 UTC 2014

What I'd like for Data.List is

uncons :: [a] -> Maybe (a, [a]).
uncons [] = Nothing
uncons (a:as) = Just (a,as)

I believe Data.Text and maybe even Data.ByteString have similar functions.
The main reason, I think:

The idiom

  x <- listToMaybe xss
  ... tail xss

is a bit ugly as the safety of tail xs depends implicitly on the fact that
listToMaybe guards it, and because it treats the head and tail completely
differently. Far prettier:

  (x,xs) <- uncons xss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list