[GHC] #10831: DeriveFunctor not capable of deriving when wrapping Either

#10831: DeriveFunctor not capable of deriving when wrapping Either -------------------------------------+------------------------------------- Reporter: htebalaka | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler | Version: 7.10.2 Keywords: | Operating System: MacOS X Architecture: | Type of failure: GHC rejects Unknown/Multiple | valid program Test Case: | Blocked By: Blocking: | Related Tickets: Differential Revisions: | -------------------------------------+------------------------------------- GHC can derive Functor for Okay, but rejects the equivalent Bad. {{{#!hs {-# LANGUAGE DeriveFunctor #-} data Okay f g a b = Inl (f a b) | Inr (g a b) deriving (Functor) newtype Bad f g a b = Bad (Either (f a b) (g a b)) deriving (Functor) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10831 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10831: DeriveFunctor not capable of deriving when wrapping Either -------------------------------------+------------------------------------- Reporter: htebalaka | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler (Type | Version: 7.10.2 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by thomie): * os: MacOS X => Unknown/Multiple * component: Compiler => Compiler (Type checker) Old description:
GHC can derive Functor for Okay, but rejects the equivalent Bad. {{{#!hs {-# LANGUAGE DeriveFunctor #-} data Okay f g a b = Inl (f a b) | Inr (g a b) deriving (Functor) newtype Bad f g a b = Bad (Either (f a b) (g a b)) deriving (Functor) }}}
New description: GHC can derive Functor for Okay, but rejects the equivalent Bad. {{{#!hs {-# LANGUAGE DeriveFunctor #-} data Okay f g a b = Inl (f a b) | Inr (g a b) deriving (Functor) newtype Bad f g a b = Bad (Either (f a b) (g a b)) deriving (Functor) }}} {{{ Can't make a derived instance of ‘Functor (Bad f g a)’: Constructor ‘Bad’ must use the type variable only as the last argument of a data type In the data declaration for ‘Bad’ }}} -- Comment: This comment (option `c`) in `compiler/typecheck/TcDeriv.hs` says this is to be expected: {{{ cond_functorOK :: Bool -> Bool -> Condition -- OK for Functor/Foldable/Traversable class -- Currently: (a) at least one argument -- (b) don't use argument contravariantly -- (c) don't use argument in the wrong place, e.g. data T a = T (X a a) -- (d) optionally: don't use function types -- (e) no "stupid context" on data type }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10831#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10831: Document conditions on deriving Functor -------------------------------------+------------------------------------- Reporter: htebalaka | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler (Type | Version: 7.10.2 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by rwbarton): * failure: GHC rejects valid program => Documentation bug Comment: Right, this is expected behavior. The compiler doesn't "look inside" the definitions of other data types when deriving Functor, it relies on Functor instances for those types. But that is not enough to handle the occurrence of `b` inside the first argument to `Either`. One would need another class {{{ class Functor1 f where fmap1 :: (a -> b) -> f a x -> f b x instance Functor1 Either }}} I note that there is no documentation in the User's Guide about when deriving Functor will succeed. That at least should be fixed, so I'm repurposing this ticket. Feel free to also submit a feature request if you like. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10831#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10831: Document conditions on deriving Functor -------------------------------------+------------------------------------- Reporter: htebalaka | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler (Type | Version: 7.10.2 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by simonpj): * cc: RyanGlScott (added) Comment: Ryan Scott made an implementation-oriented stab at documenting Functor, Foldable, Traversable here: [wiki:Commentary/Compiler/DeriveFunctor]. But I think we still lack a user-oriented specification, and such a thing would be tremendously welcome. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10831#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

But I think we still lack a user-oriented specification, and such a
#10831: Document conditions on deriving Functor -------------------------------------+------------------------------------- Reporter: htebalaka | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler (Type | Version: 7.10.2 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by RyanGlScott): Replying to [comment:3 simonpj]: thing would be tremendously welcome. What exactly would we want from a "user-oriented specification"? Do we want to see the compile-time error messages improved? Or do we want to see particular portions of the Commentary page and/or users' guide fleshed out? I'll admit that I didn't do a thorough job of how to follow along with `DeriveFunctor`'s many nuances as a newcomer to GHC in the Commentary page (I had the privilege of understanding it before I wrote it), so please point out specific parts that need work. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10831#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

Replying to [comment:3 simonpj]:
But I think we still lack a user-oriented specification, and such a
#10831: Document conditions on deriving Functor -------------------------------------+------------------------------------- Reporter: htebalaka | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler (Type | Version: 7.10.2 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by rwbarton): Replying to [comment:4 RyanGlScott]: thing would be tremendously welcome.
What exactly would we want from a "user-oriented specification"? Do we
want to see the compile-time error messages improved? Or do we want to see particular portions of the Commentary page and/or users' guide fleshed out? The user's guide should contain an explanation sufficient for a user to understand what types will and will not work with deriving Functor. Ideally this should contain examples of both sorts. The wiki is intended for developer-facing documentation; users shouldn't have to consult the wiki to find out how to use a feature. I think the errors (at least the error appearing in this ticket; I haven't looked at others if there are any) are fine, assuming that there is documentation added to the user's guide that explains in more detail what is wrong here. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10831#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10831: Document conditions on deriving Functor -------------------------------------+------------------------------------- Reporter: htebalaka | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler (Type | Version: 7.10.2 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by RyanGlScott):
The user's guide should contain an explanation sufficient for a user to understand what types will and will not work with deriving Functor. Ideally this should contain examples of both sorts.
The wiki is intended for developer-facing documentation; users shouldn't have to consult the wiki to find out how to use a feature.
OK, that makes sense. I definitely got a bit lazy by the time I got to the users' guide and more-or-less copypasted what was in the wiki—I'll try to address this when I get a chance. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10831#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10831: Document conditions on deriving Functor -------------------------------------+------------------------------------- Reporter: htebalaka | Owner: RyanGlScott Type: bug | Status: new Priority: low | Milestone: Component: Compiler (Type | Version: 7.10.2 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1293 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * owner: => RyanGlScott * differential: => Phab:D1293 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10831#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10831: Document conditions on deriving Functor
-------------------------------------+-------------------------------------
Reporter: htebalaka | Owner: RyanGlScott
Type: bug | Status: new
Priority: low | Milestone:
Component: Compiler (Type | Version: 7.10.2
checker) |
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Documentation | Unknown/Multiple
bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D1293
-------------------------------------+-------------------------------------
Comment (by Austin Seipp

#10831: Document conditions on deriving Functor -------------------------------------+------------------------------------- Reporter: htebalaka | Owner: RyanGlScott Type: bug | Status: merge Priority: low | Milestone: 8.0.1 Component: Compiler (Type | Version: 7.10.2 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1293 Wiki Page: | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: new => merge * milestone: => 8.0.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10831#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10831: Document conditions on deriving Functor -------------------------------------+------------------------------------- Reporter: htebalaka | Owner: RyanGlScott Type: bug | Status: closed Priority: low | Milestone: 8.0.1 Component: Compiler (Type | Version: 7.10.2 checker) | Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1293 Wiki Page: | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: merge => closed * resolution: => fixed Comment: Whoops. Thanks for the fix Ryan - closing this, not setting it to merge. :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10831#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC