
Why is this wrong? (...)
(...) One way to code this would be to use functional dependencies:
class MyClass r s | r -> s where function :: r -> s data MyData u = MyData u instance MyClass (MyData v) v where function (MyData a) = a
One additional problem is that I (believe I) need that my class takes just one type, since I'm trying to derive it in a new type (using generalized newtype deriving). A good comparison would be a complex number over any float type. I could define a few operations like: makeComplex r i = ComplexNumber r i realPart (ComplexNumber r _) = r But then I would like to say: newtype ComplexWithDouble = ComplexWithDouble (ComplexNumber Double) deriving ... so that I could have: a :: ComplexWithDouble a = makeComplex 0.5 0.25 My first attempt was to try some kind of "type pattern match" :) like class ComplexBaseClass (c r) where ... but it seems that doesn't make sense. Thanks for your tips, Maurício