
#9398: Data.List.cycle is not a good producer -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.8.4 Component: | Version: 7.8.3 libraries/base | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Easy (less than 1 Unknown/Multiple | hour) Type of failure: Runtime | Blocked By: performance bug | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by dfeuer): * status: closed => new * resolution: invalid => Old description:
Data.List.cycle is not a good producer. I'm not at all sure this solution is the best, but it allocates much less when mapped over and then folded. If we could make it a good consumer cheaply that would be nice too, but I imagine it's probably mostly applied to short lists, so that is probably not a priority.
{{{#!hs {-# INLINE cycle #-} cycle :: [a] -> [a] cycle [] = error "Prelude.cycle: empty list" cycle xs = concat $ repeat xs }}}
New description: Data.List.cycle is not a good producer. I ''believe'' the following fixes it. The tests I've profiled so far suggest it does so. {{{#!hs {-# INLINE cycle #-} cycle :: [a] -> [a] cycle [] = error "Empty cycle." cycle xs = let cyc = augment cycle' cyc in cyc where cycle' c n = foldr c n xs }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9398#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler