<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi--<div><br></div><div>More silly typeclass questions. &nbsp;I'm not sure the right way to ask it, so I'll start with a failed code snippet:</div><div><br></div><div><font class="Apple-style-span" face="'Courier New'">data Foo a = Foo a&nbsp;<br><br>class TwoPi a where<br>&nbsp;&nbsp;div2pi :: (Floating b) =&gt; a -&gt; b<br><br>instance (Floating a) =&gt; TwoPi (Foo a) where<br>&nbsp;&nbsp;div2pi (Foo a) = a / (2*pi)<br><br>instance TwoPi Float where<br>&nbsp;&nbsp;div2pi a = a / (2*pi)<br></font><br></div><div><br></div><div>This code is obviously meaningless, but I'm trying to figure out how you can create instances of a typeclass for data types of different kinds.</div><div><br></div><div>I have a similar piece of code that works:</div><div><br></div><div><font class="Apple-style-span" face="'Courier New'">data Foo a = Foo a&nbsp;<br><br><br>class Testable a where<br>&nbsp;&nbsp;isPos :: a -&gt; Bool<br><br>instance (Ord b, Num b) =&gt; Testable (Foo b) where<br>&nbsp;&nbsp;isPos (Foo b) = b &gt; 0<br><br>instance Testable Float where<br>&nbsp;&nbsp;isPos a = a &gt; 0<br></font><br></div><div><br></div><div>One obvious difference is that the type of isPos is a -&gt; Bool, with a defined type as the return. &nbsp;I'd rather not commit to a specific Floating type up front (I'd prefer sometimes Float sometimes Double, depending on the 'a' in Foo a, but trying to declare it as Float doesn't help me. &nbsp;This fails:</div><div><br></div><font class="Apple-style-span" face="'Courier New'">data Foo a = Foo a&nbsp;<br><br>class TwoPi a where<br>&nbsp;&nbsp;div2pi :: a -&gt; Float<br><br>instance (Floating b) =&gt; TwoPi (Foo b) where<br>&nbsp;&nbsp;div2pi (Foo b) = b / (2*pi)<br><br>instance TwoPi Float where<br>&nbsp;&nbsp;div2pi a = a / (2*pi)<br></font><br><div><br></div><div>The errors I'm getting are various permutations of:</div><div><br></div><font class="Apple-style-span" face="'Courier New'">&nbsp;&nbsp; &nbsp;Couldn't match expected type `Float' against inferred type `b'<br>&nbsp;&nbsp; &nbsp; &nbsp;`b' is a rigid type variable bound by<br>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;the instance declaration at gcbTestBad.hs:8:19<br>&nbsp;&nbsp; &nbsp;In the expression: b / (2 * pi)<br>&nbsp;&nbsp; &nbsp;In the definition of `div2pi': div2pi (Foo b) = b / (2 * pi)<br>&nbsp;&nbsp; &nbsp;In the instance declaration for `TwoPi (Foo b)'<br></font><br><div>What is the difference between these last two cases ("a -&gt; Bool" and "a -&gt; Float"), and is there anyway to make "a -&gt; b" work?&nbsp;</div><div><br></div><div>Thanks--</div><div>&nbsp;Greg</div></body></html>