<p dir="ltr">You&#39;re running into the &quot;open world&quot;assumption--anybody could come along and make Integer part of your NotAnInteger class, and there&#39;s nothing you can do to stop them. This is a design tradeoff for typeclasses: typeclass instances are always global and are exported to all other modules you use. This means you cannot ensure a type is *not* part of a typeclass. (Or, at the very least, you can&#39;t convince GHC of this fact.)</p>

<p dir="ltr">For more information about this, take a look at the following StackOverflow question: <a href="http://stackoverflow.com/questions/8728596/explicitly-import-instances">http://stackoverflow.com/questions/8728596/explicitly-import-instances</a></p>

<div class="gmail_quote">On Jul 5, 2013 8:47 AM, &quot;Nicholls, Mark&quot; &lt;<a href="mailto:nicholls.mark@vimn.com">nicholls.mark@vimn.com</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">






<div lang="EN-GB" link="blue" vlink="purple">
<div>
<p class="MsoNormal">Hello,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I largely don’t know what I’m doing or even trying to do, it is a voyage into the unknown….but….if I go…<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">&gt; {-# LANGUAGE MultiParamTypeClasses #-}<u></u><u></u></p>
<p class="MsoNormal">&gt; {-# LANGUAGE FunctionalDependencies #-}<u></u><u></u></p>
<p class="MsoNormal">&gt; {-# LANGUAGE FlexibleInstances #-}<u></u><u></u></p>
<p class="MsoNormal">&gt; {-# LANGUAGE UndecidableInstances #-}<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">&gt; class Foo x y | x -&gt; y, y -&gt; x<u></u><u></u></p>
<p class="MsoNormal">&gt; instance Foo Integer Integer<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">That seems to work….and my head seems to say…your created some sort of binary relation between 2 types…and made &lt;Integer,Integer&gt; a member of it…<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Something like that anyway….<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Then I go….<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">&gt; data Bar<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">&gt; instance Foo Bar x<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Error!....but I’m think I understand this….I can’t claim that &lt;Bar,x&gt; is a member of Foo and &lt;Integer,Integer&gt; is member of Foo and preserve my functional dependencies, because &lt;Bar,Integer&gt; is now a member of Foo..<u></u><u></u></p>

<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Bad programmer…….<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">So how I naively go….<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">&gt; class NotAnInteger a<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">&gt; instance (NotAnInteger x) =&gt; Foo Bar x<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I haven’t declared integer to be “NotAnInteger”….so (in a closed world)….this would seem to exclude the contradiction….but…<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-family:Consolas;color:#af0000">Functional dependencies conflict between instance declarations:<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-family:Consolas;color:#af0000">      instance Foo Integer Integer -- Defined at liam1.lhs:7:12<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-family:Consolas;color:#af0000">      instance NotAnInteger x =&gt; Foo Bar x -- Defined at liam1.lhs:13:12<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">So <u></u><u></u></p>
<p style="margin-left:54.0pt">
<u></u><span>i)<span style="font:7.0pt &quot;Times New Roman&quot;">                   
</span></span><u></u>I clearly don’t understand something about the type system.<u></u><u></u></p>
<p style="margin-left:54.0pt">
<u></u><span>ii)<span style="font:7.0pt &quot;Times New Roman&quot;">                  
</span></span><u></u>I don’t know how to restrict type variables in instance declarations….i.e. how do I use the notion of “Foo” across different combinations of types, without them colliding.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p><br><br>CONFIDENTIALITY NOTICE<br><br>This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further use or dissemination is prohibited.<br>
<br>While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data.<br>
<br>Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate measures to minimise these risks when e-mailing us.<br>
<br>MTV Networks International, MTV Networks UK &amp; Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks Europe.  MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc.  Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT.<br>
</p></div>

<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div>