
Hi, Am Dienstag, den 12.04.2016, 22:55 +0200 schrieb Johan Holmquist:
I propose adding two new functions to Data.List:
zipConsecutives :: [a] -> [(a,a)] zipConsecutives xs = zip xs (tail xs)
zipConsecutivesWith :: (a -> a -> b) -> [a] -> [b] zipConsecutivesWith f xs = zipWith f xs (tail xs)
(with possibly more efficient implementations)
I’m +1 on this. The fact that people debate whether tail or drop 1 is the right thing to use here point to the fact that this is less trivial than it looks. When I have to write it, it takes me a moment to think whether it is " "zip xs (tail xs)" or " "zip (tail xs) xs". Also, when _reading_ code, "zip xs (tail xs)" requires more thought than zipConsecutives. Furthermore, the standard idiom "zip xs (tail xs)" refers to its argument multiple times. It is thus not a combinator that you can put into a chain of function applications. Also, for this reason, if you compare lenths, then please compare the lengths of (\xs -> zip xs (tail xs)) with zipConsecutives And finally, an explicit name for zipConsecutives has the potential for list-fusion (see #11815 for some discussion in that direction). Greetings, Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org