On Sun, Oct 2, 2011 at 8:45 AM, Du Xi <sdiyazg@sjtu.edu.cn> wrote:
Then again , in typeclass definition how can I express the type "a->b" where "a" is the type parameter of the class and "b" is a type deduced from the rules defined in each instance of the class, which varies on a per-instance basis? e.g.

instance ExampleClass a where
   f :: a->SomeTypeWhichIsDifferentInEachInstance

What I want is some thing like this in C++:

float f(char x){ return 0.1f; }
int f(double x){ return 1; }

Use TypeFamilies.


{-# LANGUAGE TypeFamilies #}
...
type family FType a :: *
type instance FType Char = Float
type instance FType Double = Int

class ExampleClass a where
  f :: a -> FType a