[GHC] #9344: takeWhile does not participate in list fusion

GHC ghc-devs at haskell.org
Wed Jul 23 15:37:52 UTC 2014


#9344: takeWhile does not participate in list fusion
-------------------------------------+-------------------------------------
              Reporter:  dfeuer      |            Owner:
                  Type:  bug         |           Status:  new
              Priority:  normal      |        Milestone:
             Component:              |          Version:  7.8.3
  libraries/base                     |         Keywords:
            Resolution:              |     Architecture:  Unknown/Multiple
      Operating System:              |       Difficulty:  Unknown
  Unknown/Multiple                   |       Blocked By:
       Type of failure:  Runtime     |  Related Tickets:
  performance bug                    |
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------

Comment (by nomeata):

 >  One thing I'm not too clear about: what's the advantage of the
 explicitly recursive default definition over takeWhile p = foldr (\x r ->
 if p x then x:r else []) []

 Nothing per se, unless benchmarking shows that the explicit version is
 faster, I guess.

 It might even be that simply
 {{{
 takeWhile p xs = build (\kons knil -> foldr (takeWhileFB kons knil p) knil
 xs)
 {-# INLINEABLE takeWhile #-}
 }}}
 is good enough, assuming the non-inlined `takeWhile` gets compiled to good
 code (i.e. `build`, `foldr` and `takeWhileFB` are inlined). But I don’t
 have much experiences to predict that, so you’ll have to experiment and
 look at core to find out

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


More information about the ghc-tickets mailing list