
#13153: Several Traversable instances have an extra fmap -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: dfeuer Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Core Libraries | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): We have (essentially) {{{#!hs instance Traversable [] where traverse f = foldr cons_f (pure []) where cons_f x = liftA2 (:) (f x) }}} Manually copying this idea into the `ZipList` instance (I guess it's more than inlining) gives {{{#!hs instance Traversable ZipList where traverse f = foldr cons_f (pure (ZipList [])) .# getZipList where cons_f x = liftA2 (\x' ys' -> ZipList (x' : getZipList ys')) (f x) }}} The point is to fuse the final `ZipList <$>` into an operation that needs to happen anyway. `ZipList` is actually a terrible choice of example, because lists ''usually'' aren't short enough for this to matter much. But if you look at something like `First` or `Sum` it's more obviously silly. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13153#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler