Proposal: add 'equating' function to Data.List

Edward Kmett ekmett at gmail.com
Sat Jul 19 13:10:19 UTC 2014


Put in a separate proposal for Data.List.uncons. It is a reasonable, self-contained function that encourages good style. The name has been commonly used and reinvented over and over and as a top level proposal we can have any bikeshedding discussion without derailing this one.

I honestly thought it was already in there.

-Edward

> On Jul 18, 2014, at 5:19 PM, David Feuer <david.feuer at gmail.com> wrote:
> 
> 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
> 
> do
>   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:
> 
> do
>   (x,xs) <- uncons xss
>   ...
> 
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140719/86752071/attachment-0001.html>


More information about the Libraries mailing list