[GHC] #9790: Produce coercion rules for derived Functor instances

#9790: Produce coercion rules for derived Functor instances -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.9 Keywords: coercion | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Runtime Blocked By: | performance bug Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- I don't ''think'' we do this yet, but I think we probably can. If we derive a `Functor` instance, we should, whenever possible and valid, produce some sort of `fmap coerce = coerce` rule for that type. This is done manually for lists in `GHC.Base`, but I imagine it probably applies (much) more generally. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9790 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9790: Produce coercion rules for derived Functor instances -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.9 Component: Compiler | Keywords: coercion Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: Runtime | Related Tickets: performance bug | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by goldfire): Such a rule is wrong for non-lawful functors, which is why we haven't done it. It would be nice (perhaps even very nice) if we could give users a way to say that a particular instance is lawful w.r.t. the appropriate laws and would allow magic like the proposed idea. However, I'm not volunteering to design and/or implement such a system... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9790#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9790: Produce coercion rules for derived Functor instances -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.9 Component: Compiler | Keywords: coercion Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: Runtime | Related Tickets: performance bug | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by dfeuer): Replying to [comment:1 goldfire]:
Such a rule is wrong for non-lawful functors, which is why we haven't done it.
It would be nice (perhaps even very nice) if we could give users a way to say that a particular instance is lawful w.r.t. the appropriate laws and would allow magic like the proposed idea. However, I'm not volunteering to design and/or implement such a system...
Right, that's why I only mentioned ''derived'' `Functor` instances. Surely a derived instance that does not depend on any non-derived instances should be lawful! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9790#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9790: Produce coercion rules for derived Functor instances -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.9 Component: Compiler | Keywords: coercion Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: Runtime | Related Tickets: performance bug | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by goldfire): Ah -- I missed the word "derive". But, unfortunately, this still doesn't pan out in all cases: {{{ data BadFunctor a = MkBF a a deriving Show instance Functor BadFunctor where fmap f (MkBF x _) = MkBF (f x) (f x) data Wrapped f a = MkW (f a) deriving (Functor, Show) }}} `Wrapped` has a derived `Functor` instance, and yet `fmap id (MkW (MkBF True False))` is not the same as `id (MkW (MkBF True False))`. I do think your idea is sound as long as the derived `Functor` instance has no constraints. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9790#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9790: Produce coercion rules for derived Functor instances -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.9 Component: Compiler | Keywords: coercion Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: Runtime | Related Tickets: performance bug | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by dfeuer): Replying to [comment:3 goldfire]:
I do think your idea is sound as long as the derived `Functor` instance has no constraints.
That's what I was trying to get at with the bit about not depending on non-derived `Functor` instances. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9790#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9790: Produce coercion rules for derived Functor instances -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.9 Resolution: | Keywords: coercion, | deriving 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: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: coercion => coercion, deriving -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9790#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC