Original-Via: uk.ac.nsf; Mon, 7 Oct 91 21:35:30 BST
Original-Sender: postmaster <[EMAIL PROTECTED]>
Well, I am ready to scream, so I appeal to the more knowledgable gurus
on the net. The problem: I am trying to change the Complex
definition in the prelude as follows: create a general class Complex
with two instances: CartComp, which is cartesian coordinates, and
PolComp, which is polar coordinates.
I have (tentatively) defined the general class as follows (to be
expanded when I insert the polar definitions):
class (Floating a) => Complex a where
toCart :: a -> a
realPart,imagPart :: a -> Float
conjugate :: a -> a
magnitude,phase :: a -> Float
I have created a constructed type, CartComp (for Cartesion Complex)
with constructor :!+, and filled in an instance for CartComp as in
Complex in the present prelude. When I come to creating an instance
for CartComp implemanting the Complex functions above, I have the
following as a first cut:
instance (RealFloat a) => Complex (CartComp a) where
toCart x = x
realPart (x:!+y) = x
imagPart (x:!+y) = y
conjugate (x:!+y) = x :!+ (negate y)
magnitude (x:!+y) = cartmag (x:!+y)
phase (x:!+y) = cartphase (x:!+y)
The gurus here will immediately (I trust) recognize that I have typing
errors in this. The type of Float does not match the general
RealFloat in the instance definition. I cannot place RealFloat in the
definition of Complex; the rules demand a type constructor, not a
class name.
The general desire is simple: as part of the general definition of
Complex, I want to return the realpart (or imaginary part) regardless
of whether it is defined in polar or cartesion coordinates by
providing the translation function in each instance. For the life of
me, I cannot get this general definition to work. How do I do this?
H*E*L*P!!
David Barton
[EMAIL PROTECTED]