[Haskell-cafe] Functional Dependencies conflicts

Daniel Fischer daniel.is.fischer at web.de
Sat Apr 17 13:50:49 EDT 2010


Am Samstag 17 April 2010 19:14:02 schrieb Limestraël:
> Hello,
>
> Well, here comes the trouble:
> GameStructs.hs:16:9:
>     Functional dependencies conflict between instance declarations:
>       instance (Binary a) => Binarizable a a
>         -- Defined at MagBots/GameStructs.hs:16:9-37
>       instance Binarizable GameObject String
>         -- Defined at MagBots/GameStructs.hs:38:9-37
>
> GameStructs.hs:19:9:
>     Functional dependencies conflict between instance declarations:
>       instance (Binary a, Monad m) => Unbinarizable a a m
>         -- Defined at MagBots/GameStructs.hs:19:9-50
>       instance (MonadReader [GameObject] m) =>
>                Unbinarizable GameObject String m
>         -- Defined at MagBots/GameStructs.hs:41:9-73
>
> I don't see why the functional dependencies conflict, since GameObject
> is not an instance of Binary...

Somebody somewhere might write such an instance.
But more fundamentally:

GHC doesn't look at the constraints for instance selection, so your 
instance in line 16 looks like

instance Binarizable a a where ..., oh, and by the way, a must be an 
instance of Binary, otherwise please refuse to compile

to the compiler. The FunDep then says in each instance (and you'd need at 
least OverlappingInstances to declare more) a and b are the same type.
instance Binarizable GameObject String violates that FunDep.
(Analogous for Unbinarizable.)

I think removing the

instance Binary a => ...

and declaring an instance for the types you need manually is the easiest 
solution.


More information about the Haskell-Cafe mailing list