[GHC] #13061: Incorrect constraints given single flexible undecidable instance. Adding more clarification of inconsistency (was: Incorrect constraints given single flexible undecidable instance)
GHC
ghc-devs at haskell.org
Tue Jan 3 21:05:41 UTC 2017
#13061: Incorrect constraints given single flexible undecidable instance. Adding
more clarification of inconsistency
-------------------------------------+-------------------------------------
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: |
-------------------------------------+-------------------------------------
Changes (by JCarr):
* type: bug => feature request
@@ -15,2 +15,10 @@
- A function of type A a => ... will always be rejected unless Eq is also
- included.
+ Consider the functions
+ {{{#!hs
+ g :: A a => a -> a
+ g = f
+ h :: A a => a -> a
+ h = let f' = f in f
+ i = f' where
+ f' = f
+ }}}
+ h and i will both fail to typecheck.
@@ -24,0 +32,4 @@
+
+ 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.
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 :: A a => a -> a
g = f
h :: A a => a -> a
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:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list