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

GHC ghc-devs at haskell.org
Mon Jul 21 07:33:53 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):

 What general fusion work are you referring to? I only know about the
 improvements for fusing foldl, which doesn’t seem to apply here.

 Although maybe it could. How about this definition:

 {{{
 myLast2 :: [a] -> a
 myLast2 = foldl (\_ x -> x) undefined
 }}}

 While `last` yields 800051648 bytes, and `myLast` yields 560084432 bytes,
 this runs in 51648 bytes (i.e. it fuses completely).

 Admitted, the resulting code looks almost stupidly efficient (at least if
 I write `10^7` as `10000` – I’m unjustifiably surprised that that is not
 constant-folded):

 {{{
 Rec {
 $wgo
 $wgo =
   \ w_s3Aj ->
     case w_s3Aj of wild_Xf {
       __DEFAULT -> $wgo (+# wild_Xf 1);
       10000000 -> 10000000
     }
 end Rec }
 }}}

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


More information about the ghc-tickets mailing list