takeWhile&C. still not fusible
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
Trac metadata
Trac field | Value |
---|---|
Version | 7.8.2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries/base |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | ekmett, hvr |
Operating system | |
Architecture |