[GHC] #9600: Bad error message: Applicative is not a derivable class

#9600: Bad error message: Applicative is not a derivable class -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Easy (less than 1 | Type of failure: hour) | None/Unknown Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- You have `GeneralizedNewtypeDeriving` on and use `deriving Applicative` with something that you cannot derive Applicative on, GHC correctly says `cannot eta-reduce the representation type enough`. If you don't have `GeneralizedNewtypeDeriving` on yet and deriving Applicative will work, GHC says something like "perhaps you want to enable GeneralizedNewtypeDeriving"? However, if you don't have `GeneralizedNewtypeDeriving` AND if GHC figures out that if you enable it, the next message will be `cannot eta-reduce the representation type enough`, then GHC will state the most unhelpful `Applicative is not a derivable class`, which suggests to me that '''in general''', Applicative is not derivable (which is wrong). rwbarton's suggestion: Suggest enabling `GeneralizedNewtypeDeriving` in any case and then let the user see why it cannot be derived. Some relevant #ghc chat: {{{ rwbarton, that's GND again rwbarton: I a ~ K a where K = ErrorT ImmError (ReaderT CliOptions (ReaderT Config IO)) is an instance of Applicative rwbarton: so it can coerce the instance for K to an instance for I nh2: so is it the error message that is the confusing part here? It suggests that "In general, Applicative is not derivable" nh2: I mean it as: Shouldn't it give an error message like "can't derive an Applicative instance in this case because ..."? rwbarton: well maybe it could add something like "Did you mean to use GeneralizedNewtypeDeriving?" rwbarton: oh I see what you mean, even if you turn that extension on it gives the same error message nh2: yes, because we already have such a message in some cases nh2: no, in this case I had really forgotten the extension. If I add it, I get the "cannot eta-reduce the representation type enough" error, but I haven't figured out why I get it in this case yet rwbarton: I wrote the condition above basically, "I a ~ K a where K = ... is an instance of Applicative" where ~ is the coercion/isomorphism introduced by the newtype rwbarton: if you can't write down K then you can't use GND because where would it get the instance? rwbarton: writing down K is eta reduction nh2: I'm wondering whether it doesn't suggest adding the extension because it already figured out I will not be able to eta-reduce? rwbarton: oh yeah, it seems so rwbarton: that seems a bit silly nh2: in this case, I think we should pimp the error message a bit nh2: (this is the thing I want to derive bwt: https://github.com /ganeti-github-testing/ganeti- test-1/blob/master/src/Ganeti/BasicTypes.hs#L147) nh2: what do you think would be the best error message to show in such a case? nh2: just suggest the GNTD suggestion regardless and let the user see afterwards that it cannot work? rwbarton: I would just have it always suggest GND ... yeah nh2: ok I file a ticket for that rwbarton: seems like more suggestions > fewer suggestions rwbarton: even if this is a weird second-order case where there are two errors }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9600 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9600: Bad error message: Applicative is not a derivable class -------------------------------------+------------------------------------- Reporter: nh2 | Owner: JohnWiegley Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Easy (less than 1 Type of failure: | hour) None/Unknown | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by JohnWiegley): * owner: => JohnWiegley -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9600#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9600: Bad error message: Applicative is not a derivable class -------------------------------------+------------------------------------- Reporter: nh2 | Owner: JohnWiegley Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Easy (less than 1 Type of failure: | hour) None/Unknown | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by JohnWiegley): Fix pending review: https://phabricator.haskell.org/D216 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9600#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9600: Bad error message: Applicative is not a derivable class -------------------------------------+------------------------------------- Reporter: nh2 | Owner: JohnWiegley Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Easy (less than 1 Type of failure: | hour) None/Unknown | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: Phab:D216 | -------------------------------------+------------------------------------- Changes (by JohnWiegley): * differential: => Phab:D216 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9600#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9600: Bad error message: Applicative is not a derivable class
-------------------------------------+-------------------------------------
Reporter: nh2 | Owner:
| JohnWiegley
Type: bug | Status: new
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.8.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions: Phab:D216
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#9600: Bad error message: Applicative is not a derivable class -------------------------------------+------------------------------------- Reporter: nh2 | Owner: | JohnWiegley Type: bug | Status: closed Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.8.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D216 -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9600#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC