[GHC] #13293: ConstrainedClassMethods makes GeneralizedNewtypeDeriving fail

#13293: ConstrainedClassMethods makes GeneralizedNewtypeDeriving fail -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Example: {{{ {-# language GeneralizedNewtypeDeriving #-} {-# language ConstrainedClassMethods #-} instance ToDoc Int where toDoc = undefined newtype P = P Int deriving ( ToDoc ) type Doc = () class ToDoc a where toDoc :: ToDoc a => a -> Doc }}} compile with ghc-8.0.2: {{{ C.hs:6:30: error: • Couldn't match type ‘Int’ with ‘P’ arising from the coercion of the method ‘toDoc’ from type ‘ToDoc Int => Int -> Doc’ to type ‘ToDoc P => P -> Doc’ • When deriving the instance for (ToDoc P) }}} With ghc-8.0.1, it is fine. When I drop the constraint on the method declaration, ghc-8.0.2 compiles the program. This repetition of the class constraint in the method declaration actually came from a copy-paste error, so this issue does not affect my code, but it's still puzzling. Repeating the class constraint should not change the meaning of the program? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13293 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13293: ConstrainedClassMethods makes GeneralizedNewtypeDeriving fail -------------------------------------+------------------------------------- Reporter: j.waldmann | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: duplicate | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by rwbarton): * status: new => closed * resolution: => duplicate Comment: This is a duplicate of #12768; see there for much discussion. The short version is: while it would arguably be correct to be able to use GND in this particular case of a class with a method which is constrained by the same class, it's not useful enough to add special logic to GHC to handle it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13293#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC