[Haskell] functional dependency violation?

Conal Elliott conal at conal.net
Fri May 20 21:11:50 EDT 2005


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




More information about the Haskell mailing list