[Haskell-cafe] Using fundeps to resolve polymorphic types to concrete types

iavor.diatchki at gmail.com iavor.diatchki at gmail.com
Sat Aug 2 04:03:33 EDT 2008


On 7/29/08, Bryan Donlan <bd at fushizen.net> wrote:
> 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).


More information about the Haskell-Cafe mailing list