[GHC] #13153: Several Traversable instances have an extra fmap

GHC ghc-devs at haskell.org
Thu Jan 19 23:26:43 UTC 2017


#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


More information about the ghc-tickets mailing list