Yes! Sorry, I forgot a bit:<br>Binary types are automatically made instances of Binarizable/Unbinarizable (that's my line 16):<br><br>instance (Binary a) => Binarizable a a where<br> toBinary = id<br><br>instance (Binary a, Monad m) => Unbinarizable a a m where<br>
fromBinary = return<br><br><br>To me, the functional dependency in:<br>class (Binary b) => Binarizable a b | a -> b<br>meant that for each a, there only one type b that can match.<br><br>That's what I want: for every Binary type 'a', the matching Binary is also 'a'<br>
And for GameObject, the sole matching type is String.<br>In other words, GameObject implies String.<br>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...<br>
<br>Is my FunDep wrong?<br><br>I done this especially because I didn't wanted to declare each type one by one instance of Binarizable,<br>Haskell type system normally enables me to automatically define a Binary as an instance of Binarizable.<br>
<br><div class="gmail_quote">2010/4/17 Daniel Fischer <span dir="ltr"><<a href="mailto:daniel.is.fischer@web.de">daniel.is.fischer@web.de</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Am Samstag 17 April 2010 19:14:02 schrieb Limestraël:<br>
> Hello,<br>
<div class="im">><br>
> Well, here comes the trouble:<br>
> GameStructs.hs:16:9:<br>
> Functional dependencies conflict between instance declarations:<br>
> instance (Binary a) => Binarizable a a<br>
> -- Defined at MagBots/GameStructs.hs:16:9-37<br>
> instance Binarizable GameObject String<br>
> -- Defined at MagBots/GameStructs.hs:38:9-37<br>
><br>
> GameStructs.hs:19:9:<br>
> Functional dependencies conflict between instance declarations:<br>
> instance (Binary a, Monad m) => Unbinarizable a a m<br>
> -- Defined at MagBots/GameStructs.hs:19:9-50<br>
> instance (MonadReader [GameObject] m) =><br>
> Unbinarizable GameObject String m<br>
> -- Defined at MagBots/GameStructs.hs:41:9-73<br>
><br>
> I don't see why the functional dependencies conflict, since GameObject<br>
> is not an instance of Binary...<br>
<br>
</div>Somebody somewhere might write such an instance.<br>
But more fundamentally:<br>
<br>
GHC doesn't look at the constraints for instance selection, so your<br>
instance in line 16 looks like<br>
<br>
instance Binarizable a a where ..., oh, and by the way, a must be an<br>
instance of Binary, otherwise please refuse to compile<br>
<br>
to the compiler. The FunDep then says in each instance (and you'd need at<br>
least OverlappingInstances to declare more) a and b are the same type.<br>
instance Binarizable GameObject String violates that FunDep.<br>
(Analogous for Unbinarizable.)<br>
<br>
I think removing the<br>
<br>
instance Binary a => ...<br>
<br>
and declaring an instance for the types you need manually is the easiest<br>
solution.<br>
</blockquote></div><br>