1 -- | Implement ordered pairs all over again for fun (and to make sure
2 -- that we can manipulate them algebraically).
7 data TwoTuple a = TwoTuple a a
10 instance Functor TwoTuple where
11 f `fmap` (TwoTuple x1 y1) = TwoTuple (f x1) (f y1)
14 instance Num a => Num (TwoTuple a) where
15 -- Standard componentwise addition.
16 (TwoTuple x1 y1) + (TwoTuple x2 y2) =
17 TwoTuple (x1 + x2) (y1 + y2)
19 -- Standard componentwise subtraction.
20 (TwoTuple x1 y1) - (TwoTuple x2 y2) =
21 TwoTuple (x1 - x2) (y1 - y2)
23 -- Left undefined to prevent mistakes. One sane definition
24 -- would be componentwise multiplication.
25 (*) _ _ = error "multiplication of vectors is undefined"
27 abs _ = error "absolute value of vectors is undefined"
29 signum _ = error "signum of vectors is undefined"
31 fromInteger x = TwoTuple (fromInteger x) (fromInteger x)