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

GHC ghc-devs at haskell.org
Fri Apr 8 14:19:17 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 dfeuer):

 Replying to [comment:3 nomeata]:
 > If we indeed provide this function here, we might as well want to invest
 the effort to provide a well-engineered implementation. You could try to
 find out if
 >
 >  * an explicit recursion function is significantly faster and
 >  * if it is possible to write `zipConsecutive` as a good consumer or
 good producer or both, in terms of list fusion.
 >
 > David Feuer might be interested in thinking about the second point.

 I thought about something quite similar very recently! The fusion-enabled
 version would look something like this, with all the usual `RULES` noise
 added:

 {{{#!hs
 zipConsecutiveWith :: (a -> a -> b) -> [a] -> [b]
 zipConsecutiveWith f xs = build builder
   where
     builder c n = foldr go (`seq` n) xs Nothing
     go x r Nothing = r (Just x)
     go x r (Just prev) = f prev x `c` r (Just x)
 }}}

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


More information about the ghc-tickets mailing list