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

GHC ghc-devs at haskell.org
Fri Jan 20 19:42:39 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):

 Replying to [comment:5 RyanGlScott]:
 > {{{#!hs
 > newtype ZipList a = ZipList [a]
 >   deriving newtype (Functor, Foldable)
 >   deriving unsafenewtype (Traversable)
 > }}}

 Interesting. I believe this is probably safe even if the underlying
 `Applicative` and `Traversable` are bogus, thanks to polymorphism. We are
 coercing `f (t b)` to `f (u b)`. The usual concern with such a coercion is
 that `f` could have an index rather than a parameter, so matching on the
 result of the coercion could falsely reveal that `t ~ u`. But `traverse`
 can only construct `f` values using `pure`, `<*>`, and the given function.
 Of those, only the given function could produce values carrying evidence.
 But they can carry evidence only about `b`, not about `t`. So it looks
 like coercing the result of `traverse` to a representationally identical
 container with the same element type is ''probably'' okay.

 > Granted, this is a separate hack to get around the fact that we don't
 have higher-kinded roles yet, but it's (IMO) much nicer to use than having
 to manually inline the definition of `traverse` like you demonstrated
 above.

 Can you explain how higher-kinded roles would help?

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13153#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list