[Haskell-cafe] Re: Type question in instance of a class
J. Garrett Morris
jgmorris at cecs.pdx.edu
Mon Nov 17 18:07:27 EST 2008
On Mon, Nov 17, 2008 at 10:38 AM, Maurício <briqueabraque at yahoo.com> wrote:
> newtype ComplexWithDouble = ComplexWithDouble (ComplexNumber Double)
> deriving ...
Perhaps you want something like:
class Complex r c | c -> r
where makeComplex :: r -> r -> c
realPart :: c -> r
imagPart :: c -> r
data ComplexNumber t = CN t t
instance Complex t (ComplexNumber t)
where makeComplex = CN
realPart (CN r _) = r
imagPart (CN _ i) = i
newtype ComplexWithDouble = CWD (ComplexNumber Double)
deriving (Complex Double)
Having the parameters "backwards" is somewhat annoying, I suppose, but
it's unavoidable if you're hoping to use generalized newtype deriving
I believe.
/g
--
I am in here
More information about the Haskell-Cafe
mailing list