
#16322: "deriving newtype instance" generates an infinite loop -------------------------------------+------------------------------------- Reporter: paf31 | Owner: (none) Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: | 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: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): If it makes you feel any better, the code you were trying to write will be rejected with an error message in GHC 8.8 due to a slight tweak in the code generation strategy for `GeneralizedNewtypeDeriving` (notice the extra visible type applications): {{{ λ> deriving instance C a b => C (X String a) (X String b) ==================== Derived instances ==================== Derived class instances: instance Ghci1.C a b => Ghci1.C (Ghci2.X GHC.Base.String a) (Ghci2.X GHC.Base.String b) where Ghci1.c = GHC.Prim.coerce @(Data.Proxy.Proxy (Ghci2.X GHC.Base.String a_a1I3) -> GHC.Types.Int) @(Data.Proxy.Proxy (Ghci2.X GHC.Base.String a_a1I3) -> GHC.Types.Int) (Ghci1.c @(Ghci2.X GHC.Base.String a_a1I3) @b_a1I4) :: Data.Proxy.Proxy (Ghci2.X GHC.Base.String a_a1I3) -> GHC.Types.Int Derived type family instances: <interactive>:13:1: error: • Occurs check: cannot construct the infinite type: b ~ X String b arising from a functional dependency between constraints: ‘C a b’ arising from a use of ‘c’ at <interactive>:13:1-54 ‘C a b1’ arising from the instance declaration at <interactive>:13:1-54 • In the third argument of ‘GHC.Prim.coerce’, namely ‘(c @(X String a) @b)’ In the expression: GHC.Prim.coerce @(Proxy (X String a) -> Int) @(Proxy (X String a) -> Int) (c @(X String a) @b) :: Proxy (X String a) -> Int In an equation for ‘c’: c = GHC.Prim.coerce @(Proxy (X String a) -> Int) @(Proxy (X String a) -> Int) (c @(X String a) @b) :: Proxy (X String a) -> Int When typechecking the code for ‘c’ in a derived instance for ‘C (X String a) (X String b)’: To see the code I am typechecking, use -ddump-deriv <interactive>:13:1: error: • Occurs check: cannot construct the infinite type: a ~ X String a arising from a functional dependency between constraints: ‘C (X String a) b1’ arising from a use of ‘c’ at <interactive>:13:1-54 ‘C a b1’ arising from the instance declaration at <interactive>:13:1-54 • In the third argument of ‘GHC.Prim.coerce’, namely ‘(c @(X String a) @b)’ In the expression: GHC.Prim.coerce @(Proxy (X String a) -> Int) @(Proxy (X String a) -> Int) (c @(X String a) @b) :: Proxy (X String a) -> Int In an equation for ‘c’: c = GHC.Prim.coerce @(Proxy (X String a) -> Int) @(Proxy (X String a) -> Int) (c @(X String a) @b) :: Proxy (X String a) -> Int When typechecking the code for ‘c’ in a derived instance for ‘C (X String a) (X String b)’: To see the code I am typechecking, use -ddump-deriv • Relevant bindings include c :: Proxy (X String a) -> Int (bound at <interactive>:13:1) }}} ----- If this discussion answers your question, can this issue be closed? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16322#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler