[GHC] #14836: GHC fails to infer implied superclass constraint

GHC ghc-devs at haskell.org
Wed Feb 21 18:46:09 UTC 2018


#14836: GHC fails to infer implied superclass constraint
-------------------------------------+-------------------------------------
        Reporter:  crockeea          |                Owner:  (none)
            Type:  bug               |               Status:  closed
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.2
      Resolution:  duplicate         |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  GHC rejects       |  Unknown/Multiple
  valid program                      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #14417            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by RyanGlScott):

 * status:  new => closed
 * resolution:   => duplicate
 * related:   => #14417


Comment:

 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 (Monad m) => RequiresMonad m where
 }}}

 Closing as a duplicate of #14417.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14836#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list