[GHC] #11815: Data.List: Add a function to get consecutive elements (mapConsecutives)

GHC ghc-devs at haskell.org
Fri Apr 8 09:26:19 UTC 2016


#11815: Data.List: Add a function to get consecutive elements (mapConsecutives)
-------------------------------------+-------------------------------------
        Reporter:  holmisen          |                Owner:
            Type:  feature request   |               Status:  new
        Priority:  low               |            Milestone:
       Component:  libraries/base    |              Version:
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by nomeata):

 Fun fact: The definition is equivalent to
 {{{#!hs
 mapConsecutives :: (a -> a -> b) -> [a] -> [b]
 mapConsecutives f xs = zipWith f xs (tail xs)
 }}}
 because of lazyness and `zipWith _ [] _ = []`. But it might still not be
 worth inlining it, as it cannot not fuse with `xs` for various reasons.

 No strong opinion on this function, but I would not object. Is there a
 better name that immediatelly gives away what it does?

 Also, in the interest of smaller building blocks, should we maybe provide
 {{{#!hs
 consecutiveElements:: [a] -> [(a,a)]
 consecutiveElements xs = zip xs (tail xs)
 }}}
 instead? Again, better name wanted. It also has a slightly more helpful
 type signature.

 Or provide both, similar to `zip` and `zipWith`.

 How about the names `zipConsecutive` and `zipConsecutiveWith`? By their
 analogies to `zip` and `zipWith`, the usage should be pretty clear.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11815#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list