[GHC] #9355: scanr does not participate in stream fusion

GHC ghc-devs at haskell.org
Thu Jul 24 22:36:17 UTC 2014


#9355: scanr does not participate in stream fusion
-------------------------------------+-------------------------------------
              Reporter:  dfeuer      |            Owner:
                  Type:  bug         |           Status:  new
              Priority:  normal      |        Milestone:  7.8.4
             Component:              |          Version:  7.8.3
  libraries/base                     |         Keywords:
            Resolution:              |     Architecture:  Unknown/Multiple
      Operating System:              |       Difficulty:  Moderate (less
  Unknown/Multiple                   |  than a day)
       Type of failure:  Runtime     |       Blocked By:
  performance bug                    |  Related Tickets:
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------

Comment (by dfeuer):

 OK, so it didn't turn out to be quite as trivial as I thought, but it
 looks like this does the trick:

 {{{#!haskell
 scanr :: forall a b . (a -> b -> b) -> b -> [a] -> [b]
 scanr f q0 ls = build scr
   where
    scr :: forall c . (b -> c -> c) -> c -> c
    scr c n = snd $ foldr go (q0, q0 `c` n) ls
      where
        go x (r,est) = let fxr = f x r in (fxr, fxr `c` est)
 }}}

 Fortunately, the tuples get unboxed as they should. Some extra rules may
 be needed for map, et al.

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


More information about the ghc-tickets mailing list