[GHC] #9339: last is not a good consumer

GHC ghc-devs at haskell.org
Mon Jul 21 08:09:48 UTC 2014


#9339: last is not a good consumer
-------------------------------------+-------------------------------------
              Reporter:  dfeuer      |             Owner:
                  Type:  bug         |            Status:  new
              Priority:  normal      |         Milestone:
             Component:              |           Version:  7.8.3
  libraries/base                     |          Keywords:
            Resolution:              |  Operating System:  Unknown/Multiple
Differential Revisions:              |   Type of failure:  Runtime
          Architecture:              |  performance bug
  Unknown/Multiple                   |         Test Case:
            Difficulty:  Unknown     |          Blocking:
            Blocked By:              |
       Related Tickets:              |
-------------------------------------+-------------------------------------

Comment (by nomeata):

 >  That looks wonderful. Is it certain to be changed to a foldl' in cases
 where it doesn't fuse?

 Hopefully not. `foldl'` would force the accumulator, which we do *not*
 want here (otherwise the `undefined` would be forced, or `last [undefined,
 1]` would not work).

 I didn’t do further testing with that idea, it just crossed my mind. It
 maybe the that this implementation is only good when fusing works – would
 you mind trying to find out?

 In that case one would have to do the `replace, try to fuse, replace back`
 trick (which might be tricky with `foldl` itself getting inlined).

 Or maybe it is possible to use `foldl` and wrap the argument in a `Id`, so
 that forcing does the right thing.

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


More information about the ghc-tickets mailing list