
#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: | -------------------------------------+------------------------------------- Comment (by dfeuer): Replying to [comment:12 nomeata]:
I think you need to move the knot-tying into the argument to build, e.g. something like {{{ cycle xs = build $ \c _ -> let cyc = foldr c cyc xs in cyc }}} (ignoring the issue of `cycle []` for now)
It seems that this would be both a good producer, and possibly even a good consumer.
I won't be able to test anything for some hours, but that does look very promising indeed. I wonder if GHC performed some transformation that turned mine into yours somehow, but yours is definitely much clearer and prettier in any case. I ''think'' it's a good producer, and a good consumer for `build`. It doesn't look like a perfect consumer for `augment` (although it's not a ''bad'' one), but that may be unavoidable. I believe `cycle` is one of the more popular list functions in production code, so personally I think it's probably worth giving up the error message on a null argument to buy a little performance, even on the consumption side, but it's also true that the production side is more important in general. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9398#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler