The program below fails to compile under ghc 6.4, giving the following error message: c:/conal/Eros/Haskell/PTest.hs:13:0: Illegal instance declaration for `Path (PCompose po pi) a a' whole whole'' (the instance types do not agree with the functional dependencies of the class) In the instance declaration for `Path (PCompose po pi) a a' whole whole'' Failed, modules loaded: none. I'm stumped. Can anyone explain how this instance violates the functional dependencies? - Conal -- Experimenting with paths and type classes -- whole' is whole with a replaced by a' at p. pathApp applies a function -- at p in whole. class Path p a a' whole whole' | p a a' whole -> whole' , p whole whole' -> a a' where pathApp :: p -> (a -> a') -> whole -> whole' data PCompose a b = PC a b instance (Path pi a a' mid mid', Path po mid mid' whole whole') => Path (PCompose po pi) a a' whole whole' where pathApp (PC po pi) = pathApp po . pathApp pi -- ... other instances
Hi, On 20-May-2005, Conal Elliott <conal@conal.net> wrote:
The program below fails to compile under ghc 6.4, giving the following error message:
c:/conal/Eros/Haskell/PTest.hs:13:0: Illegal instance declaration for `Path (PCompose po pi) a a' whole whole'' (the instance types do not agree with the functional dependencies of the class) In the instance declaration for `Path (PCompose po pi) a a' whole whole'' Failed, modules loaded: none.
I'm stumped. Can anyone explain how this instance violates the functional dependencies?
The problem is that whole' can't be determined from po, pi, a, a' and whole, therefore the first functional dependency is not met. The two constraints on the instance and the two functional dependencies on the class induce the following four dependencies between the type variables in the instance: pi a a' mid -> mid' pi mid mid' -> a a' po mid mid' whole -> whole' po whole whole' -> mid mid' None of these rules can fire given po, pi, a, a' and whole, which means that no other variables are determined from them. Cheers, Mark.
participants (2)
-
Conal Elliott -
Mark Brown