[GHC] #14417: Overly specific instances may not be resolved

#14417: Overly specific instances may not be resolved -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.3 (Type checker) | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: GHC rejects Unknown/Multiple | valid program Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{#!hs {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE UndecidableInstances #-} class A x class A x => B x class A x => C x instance B x => C x }}} produces {{{ BrokenSuper.hs:8:10: error: • Could not deduce (A x) arising from the superclasses of an instance declaration from the context: B x bound by the instance declaration at BrokenSuper.hs:8:10-19 Possible fix: add (A x) to the context of the instance declaration • In the instance declaration for ‘C x’ | 8 | instance B x => C x }}} This was noticed in [https://stackoverflow.com/questions/47093627/can-not- deduce-superclass this SO question] and reduced by Daniel Wagner. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14417 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14417: Overly specific instances may not be resolved -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler (Type | Version: 8.3 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 Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfeuer): * Attachment "BrokenSuper.trace" added. Results of -ddump-tc-trace -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14417 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14417: Overly specific instances may not be resolved -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler (Type | Version: 8.3 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 Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfeuer): * Attachment "BrokenSuper.cstrace" added. Results of -ddump-cs-trace -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14417 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

The compiler is now a bit more conservative in solving constraints
#14417: Overly specific instances may not be resolved -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler (Type | Version: 8.3 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 Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): This is expected behavior. From the [https://downloads.haskell.org/~ghc/8.0.1/docs/html/users_guide/8.0.1-notes.h... GHC 8.0.1 release notes]: previously provided by superclasses (see Trac #11762). For instance, consider this program,:
{{{#!hs {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE UndecidableInstances #-}
class Super a class (Super a) => Left a class (Super a) => Right a instance (Left a) => Right a -- this is now an error }}}
GHC now rejects this instance, claiming it cannot deduce the `Super a`
superclass constraint of the `Right` typeclass. This stands in contrast to previous releases, which would accept this declaration, using the `Super a` constraint implied by the `Left a` constraint. To fix this simply add the needed superclass constraint explicitly,
{{{#!hs instance (Left a, Super a) => Right a }}}
In other words, it's a limitation that was imposed after the introduction of `UndecidableSuperClasses`. So from GHC's perspective, the correct thing to do here is to use this instance declaration instead: {{{#!hs instance A x => C x }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14417#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14417: Overly specific instances may not be resolved -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.4.1 Component: Compiler (Type | Version: 8.3 checker) | Resolution: duplicate | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: #11762 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfeuer): * status: new => closed * resolution: => duplicate * related: => #11762 Comment: That's really quite strange, but this is clearly a duplicate. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14417#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC