I was kinda surprised when I read the source code of instances of Applicative Complex
and Monad Complex
from GHC Data.Complex
module:
-- | @since 4.9.0.0
instance Applicative Complex where
pure a = a :+ a
f :+ g <*> a :+ b = f a :+ g b
liftA2 f (x :+ y) (a :+ b) = f x a :+ f y b
-- | @since 4.9.0.0
instance Monad Complex where
a :+ b >>= f = realPart (f a) :+ imagPart (f b)
What the...? The Applicative Complex
instance seems to treat complex numbers as just size-two arrays. And they both seem more like arrow operations. Is there any mathematical basis behind them? Either there is or not, what are they used for?