Type inference fails with closed type families
Consider the following module:
{-# LANGUAGE TypeFamilies #-}
module M where
type family D d a where
D () a = Bool
data Descr d = Descr {
fld :: D d Double
}
--descrIn :: (D d Double ~ Bool) => Descr d
descrIn = Descr { fld = True }
I expected ghc to infer the commented out type signature, but instead I get an error:
$ ghc -Wall -c ./test/M.hs
test\M.hs:12:25:
Couldn't match expected type `D d0 Double' with actual type `Bool'
The type variable `d0' is ambiguous
Relevant bindings include
descrIn :: Descr d0 (bound at test\M.hs:12:1)
In the `fld' field of a record
In the expression: Descr {fld = True}
Uncommenting the type signature makes the module compile.
As an aside, the signature I really want ghc to deduce is
descrIn :: Descr ()
But since ghc doesn't (yet) use the full information provided by the closed type family equations this doesn't happen. Still, it should be able to figure out the commented out one.
Trac metadata
Trac field | Value |
---|---|
Version | 7.8.2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |