Incorrect ambiguity error with functional dependencies
GHC reject a program as ambiguous when it is not. Consider the following example:
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleContexts #-}
class C a b | a -> b where
f :: a -> b
test :: (Show a, C Int a) => Bool
test = show (f (1 :: Int)) == "1"
GHC rejects the program with the following error:
Ambiguous constraint `C Int a'
At least one of the forall'd type variables mentioned by the constraint
must be reachable from the type after the '=>'
In the type signature for `test': test :: (Show a, C Int a) => Bool
The only variable, a
, is fully determined by the type Int
via the functional dependency on class C
so there is no ambiguity.
These sort of errors crop up when we desugar implicit parameters into uses of the IP
class (which has a functional dependency).
Trac metadata
Trac field | Value |
---|---|
Version | 7.4.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler (Type checker) |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |