A data type representing complex numbers.
You can read about complex numbers on wikipedia.
In haskell, complex numbers are represented as a :+ b which can be thought of
as representing a + bi. For a complex number z, abs z is a number with the magnitude of z,
but oriented in the positive real direction, whereas signum z
has the phase of z, but unit magnitude.
Apart from the loss of precision due to IEEE754 floating point numbers,
it holds that z == abs z * signum z.
Note that Complex's instances inherit the deficiencies from the type
parameter's. For example, Complex Float's Ord instance has similar
problems to Float's.
As can be seen in the examples, the Foldable and Traversable instances traverse the real part first.
Examples
(5.0 :+ 2.5) + 6.511.5 :+ 2.5
abs (1.0 :+ 1.0) - sqrt 2.00.0 :+ 0.0
abs (signum (4.0 :+ 3.0))1.0 :+ 0.0
foldr (:) [] (1 :+ 2)[1,2]
mapM print (1 :+ 2)12
Constructors
a :+ ainfix 6forms a complex number from its real and imaginary rectangular components.
Instances24Monad, Functor, MonadFix, Applicative, Foldable, Traversable, …
Monad ComplexDefined in base-4.20.2.0 · Data.ComplexFunctor ComplexDefined in base-4.20.2.0 · Data.ComplexMonadFix ComplexDefined in base-4.20.2.0 · Data.ComplexApplicative ComplexDefined in base-4.20.2.0 · Data.ComplexFoldable ComplexDefined in base-4.20.2.0 · Data.ComplexTraversable ComplexDefined in base-4.20.2.0 · Data.ComplexMonadZip ComplexDefined in base-4.20.2.0 · Data.ComplexFoldable1 ComplexDefined in base-4.20.2.0 · Data.Foldable1Eq1 ComplexDefined in base-4.20.2.0 · Data.Functor.ClassesExample1 expression eq1 (1 :+ 2) (1 :+ 2)True
Example1 expression eq1 (1 :+ 2) (1 :+ 3)False
Read1 ComplexDefined in base-4.20.2.0 · Data.Functor.ClassesExample1 expression readPrec_to_S readPrec1 0 "(2 % 3) :+ (3 % 4)" :: [(Complex Rational, String)][(2 % 3 :+ 3 % 4,"")]
Show1 ComplexDefined in base-4.20.2.0 · Data.Functor.ClassesExample1 expression showsPrec1 0 (2 :+ 3) """2 :+ 3"
Generic1 ComplexDefined in base-4.20.2.0 · Data.ComplexEq a => Eq (Complex a)Defined in base-4.20.2.0 · Data.ComplexRealFloat a => Floating (Complex a)Defined in base-4.20.2.0 · Data.ComplexRealFloat a => Fractional (Complex a)Defined in base-4.20.2.0 · Data.ComplexData a => Data (Complex a)Defined in base-4.20.2.0 · Data.ComplexRealFloat a => Num (Complex a)Defined in base-4.20.2.0 · Data.ComplexRead a => Read (Complex a)Defined in base-4.20.2.0 · Data.ComplexShow a => Show (Complex a)Defined in base-4.20.2.0 · Data.ComplexGeneric (Complex a)Defined in base-4.20.2.0 · Data.ComplexStorable a => Storable (Complex a)Defined in base-4.20.2.0 · Data.ComplexNFData a => NFData (Complex a)Defined in deepseq-1.5.0.0 · Control.DeepSeqtype Rep (Complex a) = D1 ('MetaDataDefined in base-4.20.2.0 · Data.Complex"Complex"
"Data.Complex"
"base"
'False) (C1 ('MetaCons":+"
('InfixI 'NotAssociative6
) 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)))type Rep1 Complex = D1 ('MetaDataDefined in base-4.20.2.0 · Data.Complex"Complex"
"Data.Complex"
"base"
'False) (C1 ('MetaCons":+"
('InfixI 'NotAssociative6
) 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1 :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1))