module FRP.Spice.Math.Vector where
import Control.Applicative
import Data.Default
import Data.Monoid
data Vector a = Vector a a
instance Default a => Default (Vector a) where
def = Vector def def
instance Show a => Show (Vector a) where
show (Vector x y) = mconcat ["Vector ", show x, " ", show y]
instance Num a => Num (Vector a) where
(Vector x1 y1) + (Vector x2 y2) = Vector (x1 + x2) (y1 + y2)
(Vector x1 y1) * (Vector x2 y2) = Vector (x1 * x2) (y1 * y2)
fromInteger n = Vector (fromInteger n) (fromInteger n)
abs (Vector x y) = Vector (abs x) (abs y)
signum (Vector x y) = Vector (signum x) (signum y)
negate (Vector x y) = Vector (negate x) (negate y)
instance Functor Vector where
fmap fn (Vector x y) = Vector (fn x) (fn y)
instance Applicative Vector where
pure a = Vector a a
(Vector fn _) <*> (Vector x y) = Vector (fn x) (fn y)
scalar :: Num a => Vector a -> a -> Vector a
scalar (Vector x y) n = Vector (x * n) (y * n)