Skip to content

Instantly share code, notes, and snippets.

@walseb
Created April 26, 2020 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walseb/1e0a0ca98aaa9469ab5da04e24f482c2 to your computer and use it in GitHub Desktop.
Save walseb/1e0a0ca98aaa9469ab5da04e24f482c2 to your computer and use it in GitHub Desktop.
VectorSpace implemented using linear
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
import FRP.Yampa
import Linear as L
instance (Eq a, Floating a) => VectorSpace (V1 a) a where
zeroVector = L.zero
(*^) = (L.*^)
(^/) = (L.^/)
negateVector = L.negated
(^+^) = (L.^+^)
(^-^) = (L.^-^)
dot = L.dot
instance (Eq a, Floating a) => VectorSpace (V2 a) a where
zeroVector = L.zero
(*^) = (L.*^)
(^/) = (L.^/)
negateVector = L.negated
(^+^) = (L.^+^)
(^-^) = (L.^-^)
dot = L.dot
-- You could keep going with V3, V4, etc but you get the idea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment