[Haskell-cafe] looking for examples of non-full FunctionalDependencies

Claus Reinke claus.reinke at talk21.com
Thu Apr 17 20:00:40 EDT 2008

> Sorry to be picky but there is no violation of the FD here.  Note that
> the class D has only a single ground instance and to violate an FD you
> need at least two.  

perhaps you are thinking of functional dependencies as
being defined extensionally, over the extent of the type
relations specified by multiparameter type classes?

somewhat counterintuitively, this isn't quite the case
(just as instance selection doesn't take contexts into
account..). to get an FD conflict, it is sufficient to have 
two conflicting constraints, no need for any instances.


    module Fail(Fail) where 
    class X a
    class X a => Fail a

    module Main where
    import Fail
    class C a b | a -> b
    instance Fail a => C [a] Bool

since superclass X has no instances and is not exported from 
module Fail, class Fail, though exported, can have no instances.

so the instance declaration given for C seems entirely useless, 
as far as the relation over types is concerned - there are no 
ground instances of C. nevertheless, it is taken into account 
when considering functional dependencies:

    :t undefined :: C [a] b => (a,b)
    undefined :: C [a] Bool => (a,Bool)

and so adding an instance for 'C [a] Char' would lead to an
FD conflict.

just checking, 

More information about the Haskell-Cafe mailing list