<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>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.</div><div><br></div><div>I honestly thought it was already in there.</div><div><br>-Edward</div><div><br>On Jul 18, 2014, at 5:19 PM, David Feuer <<a href="mailto:david.feuer@gmail.com">david.feuer@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><p dir="ltr">What I'd like for Data.List is</p>
<p dir="ltr">uncons :: [a] -> Maybe (a, [a]).<br>
uncons [] = Nothing<br>
uncons (a:as) = Just (a,as)</p>
<p dir="ltr">I believe Data.Text and maybe even Data.ByteString have similar functions. The main reason, I think:</p>
<p dir="ltr">The idiom</p>
<p dir="ltr">do<br>
  x <- listToMaybe xss<br>
  ...<br>
  ... tail xss<br>
  ...</p>
<p dir="ltr">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:</p>
<p dir="ltr">do<br>
  (x,xs) <- uncons xss<br>
  ...</p>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Libraries mailing list</span><br><span><a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a></span><br><span><a href="http://www.haskell.org/mailman/listinfo/libraries">http://www.haskell.org/mailman/listinfo/libraries</a></span><br></div></blockquote></body></html>