[GHC] #9132: takeWhile&C. still not fusible

GHC ghc-devs at haskell.org
Wed May 21 01:32:15 UTC 2014


#9132: takeWhile&C. still not fusible
-------------------------------------+-------------------------------------
       Reporter:  Blaisorblade       |             Owner:
           Type:  bug                |            Status:  new
       Priority:  normal             |         Milestone:
      Component:  libraries/base     |           Version:  7.8.2
       Keywords:  fusion             |  Operating System:  Unknown/Multiple
   Architecture:  Unknown/Multiple   |   Type of failure:  Runtime
     Difficulty:  Moderate (less     |  performance bug
  than a day)                        |         Test Case:
     Blocked By:                     |          Blocking:
Related Tickets:                     |
-------------------------------------+-------------------------------------
 takeWhile is not still fusible, 2 1/2 years after this report:

 http://www.haskell.org/pipermail/glasgow-haskell-
 users/2011-December/021299.html

 The discussion suggests making takeWhile a good producer/consumer with
 foldr/build fusion:

 takeWhile' :: (a -> Bool) -> [a] -> [a]
 takeWhile' p xs = build $ \c n -> foldr (takeWhileF p c n) n xs
 {-# INLINE takeWhile' #-}

 takeWhileF p c n x xs = if p x then x `c` xs else n

 Furthermore, the discussion suggests having rewrite rules to go to this
 version and then rewrite back (if fusion fails).

 The report also mentions concatMap (which is a separate known problem). It
 also mentions drop and dropWhile, but I don't see when they perform
 allocations, so I think that's an erroneous request.

 I experienced the bug on GHC 7.6.3, but it seems still there in
 base-4.7.0.0, judging from the source:
 http://hackage.haskell.org/package/base-4.7.0.0/docs/src/GHC-
 List.html#takeWhile

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


More information about the ghc-tickets mailing list