<div dir="ltr"><div>That is certainly an improvement to using tail for this situation.<br><br></div>The proposal still stands though for reasons of general utility. It is preferable to not having to repeat the variable name for example.<br><div><div><div class="gmail_extra"><br><div class="gmail_quote">2016-04-13 8:47 GMT+02:00 David Turner <span dir="ltr"><<a href="mailto:dct25-561bs@mythic-beasts.com" target="_blank">dct25-561bs@mythic-beasts.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Hi there,</p>
<p dir="ltr">The idiom I normally use for this is 'zip xs (drop 1 xs)'. By using 'drop 1' instead of 'tail' it handles the empty case without partiality or needing an extra equation. Does that work for you?</p>
<p dir="ltr">Cheers,</p>
<p dir="ltr">David</p>
<div class="gmail_quote"><div><div class="h5">On 12 Apr 2016 21:55, "Johan Holmquist" <<a href="mailto:holmisen@gmail.com" target="_blank">holmisen@gmail.com</a>> wrote:<br type="attribution"></div></div><blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">I propose adding two new functions to Data.List:<br><br> zipConsecutives :: [a] -> [(a,a)]<br> zipConsecutives xs = zip xs (tail xs)<br><br> zipConsecutivesWith :: (a -> a -> b) -> [a] -> [b]<br> zipConsecutivesWith f xs = zipWith f xs (tail xs)<br><br>(with possibly more efficient implementations)<br><br>The Trac feature request is at <a href="https://ghc.haskell.org/trac/ghc/ticket/11815" target="_blank">https://ghc.haskell.org/trac/ghc/ticket/11815</a>.<br><br><br>Why<br><br>These functions are useful when one wants to process consecutive pairs<br>of elements in a sequence, which is not uncommon. The ticket lists<br>some examples, reiterated here:<br><br> -- diff consecutive elements:<br> diffs = zipConsecutivesWith (flip (-))<br><br> -- determine if list is ascending (similar for descending and strict):<br> isAscending = and . zipConsecutivesWith (<=)<br><br> -- an old friend of ours:<br> fibs = 1 : 1 : zipConsecutivesWith (+) fibs<br><br> -- get the edges of a closed path defined by points (ps):<br> edges ps = zipConsecutivesWith makeEdge (ps ++ take 1 ps)<br><br><br>Why add to Data.List (and base)<br><br>The definition must either use an extra equation for the empty list case:<br><br> zipConsecutives [] = []<br> zipConsecutives xs = zip xs (tail xs)<br><br>which makes it non practical to define inline at each use site. Or one<br>may omit the empty list equation, which is safe (thanks to laziness),<br>but that may not be immediately obvious. (It wasn't to me anyway.) The<br>tail function is generally considered unsafe so it is not desirable to<br>force the user to use it. The proposed functions would offer an<br>alternative.<br><br><br>The Data.List module is often imported unqualified, so new identifiers<br>may cause collissions. I do find it rather unlikely that the proposed<br>names would cause such problems, however.<br><br><br>Deadline for discussion: 2016-05-31.<br></div>
<br></div></div><span class="">_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
<br></span></blockquote></div>
</blockquote></div><br></div></div></div></div>