
Hi,
On 7/29/08, Bryan Donlan
Hi,
Is there any theoretical reason that functional dependencies can't be used to resolve a polymorphic type to a concrete type? For example:
-- compile with -fglasgow-exts
class DeriveType a b | a -> b
data A = A data B = B
instance DeriveType A B
simpleNarrow :: DeriveType A b => b -> B simpleNarrow = id
Since 'b' is uniquely determined by the fundep in DeriveType, it seems that this ought to work; ie, since the only type equation satisfying DeriveType A b is B -> B, it should reduce to that before trying to fit its type against its body.
According to the theory of functional dependencies this function should type check but there is a bug in the current implementation (or you may view it as an incompleteness---the compiler is not smart enough to infer that "b" in this case is really "B" while checking the signature). Iavor