<br><br><div class="gmail_quote">On Sun, Oct 2, 2011 at 8:45 AM, Du Xi <span dir="ltr">&lt;<a href="mailto:sdiyazg@sjtu.edu.cn">sdiyazg@sjtu.edu.cn</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">Then again , in typeclass definition how can I express the type &quot;a-&gt;b&quot; where &quot;a&quot; is the type parameter of the class and &quot;b&quot; is a type deduced from the rules defined in each instance of the class, which varies on a per-instance basis? e.g.</div>
</div>
<br>
instance ExampleClass a where<br>
    f :: a-&gt;<u></u>SomeTypeWhichIsDifferentInEach<u></u>Instance<br>
<br>
What I want is some thing like this in C++:<br>
<br>
float f(char x){ return 0.1f; }<br>
int f(double x){ return 1; }</blockquote><div><br></div><div>Use TypeFamilies.</div><div><br></div><div><br></div><div>{-# LANGUAGE TypeFamilies #}</div><div>...</div><div>type family FType a :: *</div><div>type instance FType Char = Float</div>
<div>type instance FType Double = Int</div><div><br></div><div>class ExampleClass a where</div><div>  f :: a -&gt; FType a</div><div><br></div></div>