Hi, I'm trying to use functionally dependent typeclasses to create an overloaded (+=) function. A simplified example of a first bit of code is...
class PlusEq a b c | a b -> c where (+=) :: a -> b -> c instance (MArray a e m, Num e, Ix i) => PlusEq (a i e) (a i e) (m ()) where (+=) x y = let updateX i = do xi <- readArray x i yi <- readArray y i writeArray x i (xi + yi) in sequence_ . map updateX $ indices x I keep getting this error in GHCi: Illegal instance declaration for `PlusEq (a i e) (a i e) (m ())' (the instance types do not agree with the functional dependencies of the class) In the instance declaration for `PlusEq (a i e) (a i e) (m ())' Failed, modules loaded: none. Looking at GHC's documentation for MArray, the definition starts out class (HasBounds a, Monad m) => MArray a e m where ... It seems to me if MArray were written using fundeps (something like MArray a e m | a e -> m) things may work out. Is there a reason it's not written this way? If so, is there another way to do what I'm trying to do? Thanks. Chad Scherrer Computational Mathematics Group Pacific Northwest National Laboratory "Time flies like an arrow; fruit flies like a banana." -- Groucho Marx _______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell