
#8390: regression in handling of type variables in constraints on instances which do not appear in the instance head ----------------------------------------------+---------------------------- Reporter: aavogt | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects valid program | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ----------------------------------------------+---------------------------- Comment (by simonpj): Consider: {{{ f :: Num a => Int -> Int f = blah instance Num a => C Int where blah }}} Both cases, calling `f` or using the instance, will give rise to an ambiguous constraint `Num a`. So both are rejected in the same way. But functions with an ambiguous times may ''sometimes'' be callable. Eg {{{ class C a b where ... f :: C a b => a -> Int f = blah instance C a b => Eq [a] where blah }}} The type of `f` is ambiguous, in the sense that if we said {{{ g :: C a b => a -> Int -- Identical g = f }}} type checking would fail even. But at ''certain'' types, typechecking might succeed. Example {{{ instance C Char b where blah foo = f 'x' }}} The `-XAllowAmbiguousTypes` flag therefore tells GHC to accept f's type even if it's ambiguous. Thus, GHC's definition of "ambiguous" is "over-eager" in the sense that the function ''can'' be called at some types, although perhaps not at others. Hence the flag. I don't know a less-eager-but-still-useful definition. Certainly, I got lots of Trac tickets before saying "I had a definition f=e; I got ghci to tell me its type; I pasted in that type as a type signature for f, and it didn't typecheck". That was because the inferred type was ambiguous. Same with instance decls. The error message now says {{{ T8390.hs:14:10: Could not deduce (Fun g a b0) arising from the ambiguity check for an instance declaration from the context (Fun f b c, Fun g a b) bound by an instance declaration: (Fun f b c, Fun g a b) => Fun (Compose f g) a c at T8390.hs:14:10-56 The type variable ‛b0’ is ambiguous In the ambiguity check for: forall f g a c b. (Fun f b c, Fun g a b) => Fun (Compose f g) a c To defer the ambiguity check to use sites, enable AllowAmbiguousTypes In the instance declaration for ‛Fun (Compose f g) a c’ }}} and adding `-XAllowAmbiguousTypes` makes it go through. OK? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8390#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler