[GHC] #13061: Incorrect constraints given single flexible undecidable instance. (was: Incorrect constraints given single flexible undecidable instance. Adding more clarification of inconsistency)

GHC ghc-devs at haskell.org
Tue Jan 3 21:07:20 UTC 2017


#13061: Incorrect constraints given single flexible undecidable instance.
-------------------------------------+-------------------------------------
        Reporter:  JCarr             |                Owner:
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler (Type    |              Version:  8.0.1
  checker)                           |             Keywords:  Constraint,
      Resolution:                    |  UndecidableInstances,
                                     |  FlexibleInstances
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:                    |
-------------------------------------+-------------------------------------
Description changed by JCarr:

@@ -17,1 +17,1 @@
- g :: A a => a -> a
+ g, h, i :: A a => a -> a
@@ -19,1 +19,0 @@
- h :: A a => a -> a

New description:

 If a class has an instance in the form F a => G a in its file, and no
 other instances, then the functions in G a will have the constraint F a,
 rather than G a.

 Example file
 {{{#!hs
 {-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
 class A a where
     f :: a -> a
 instance {-# OVERLAPPABLE #-} Eq a => A a where
     f = id
 }}}

 f will have type Eq a => a -> a -> Bool.
 Consider the functions
 {{{#!hs
 g, h, i :: A a => a -> a
 g = f
 h = let f' = f in f
 i = f' where
     f' = f
 }}}
 h and i will both fail to typecheck.

 If we add:
 {{{#!hs
 instance A Int where
     f = id
 }}}
 Then f will have the correct type A a => a -> a -> Bool.

 This has been closed previously, but the contrast between g and h above is
 worth the reconsideration, as it makes some valid functions not definable
 unless an instance is added.

--

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


More information about the ghc-tickets mailing list