Yes! Sorry, I forgot a bit:
Binary types are automatically made instances of Binarizable/Unbinarizable (that's my line 16):
instance (Binary a) => Binarizable a a where
toBinary = id
instance (Binary a, Monad m) => Unbinarizable a a m where
fromBinary = return
To me, the functional dependency in:
class (Binary b) => Binarizable a b | a -> b
meant that for each a, there only one type b that can match.
That's what I want: for every Binary type 'a', the matching Binary is also 'a'
And for GameObject, the sole matching type is String.
In other words, GameObject implies String.
I would have undestood the error if GameObject was also an instance of Binary (then the two instances would match), but it's not the case...
Is my FunDep wrong?
I done this especially because I didn't wanted to declare each type one by one instance of Binarizable,
Haskell type system normally enables me to automatically define a Binary as an instance of Binarizable.
Am Samstag 17 April 2010 19:14:02 schrieb Limestraël:
> Hello,
>Somebody somewhere might write such an instance.
> 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...
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.