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

GHC ghc-devs at haskell.org
Fri Nov 3 18:27:22 UTC 2017


#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.html#language
 GHC 8.0.1 release notes]:

 > The compiler is now a bit more conservative in solving constraints
 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


More information about the ghc-tickets mailing list