deriving (Show, Eq)
--- | By making Cardinal an instance of Num, we gain the ability to
+-- | By making Cardinal an instance of 'Num', we gain the ability to
-- add, subtract, and multiply directions. The results of these
-- operations are never actually calculated; the types just keep
-- track of which operations were performed in which order.
x + y = Sum x y
x - y = Difference x y
x * y = Product x y
- negate x = Product (Scalar (-1)) x
+ negate = Product (Scalar (-1))
abs x = x
signum x = x
fromInteger x = Scalar (fromIntegral x)
-- take quotients of directions.
instance Fractional Cardinal where
x / y = Quotient x y
- recip x = Quotient (Scalar 1) x
+ recip = Quotient (Scalar 1)
fromRational x = Scalar (fromRational x)