data Vector a = Vector a a a deriving (Eq, Show)
instance Functor Vector where
fmap f (Vector x y z) = Vector (f x) (f y) (f z)
So far so good.
instance Num ((Num a) => Vector a) where
negate = fmap negate
Doesn’t work. I tried many different variations on that first line but GHC keeps complaining. I want to make a Vector containing numbers an instance of Num; surely this should be possible? Otherwise I would have to make an instance for Int, Integer, Float, Double, etc. all with the same definition.
Consider writing other methods too.
(You can write
deriving (Eq, Show, Functor)if you turn on-XDeriveFunctor.)