Skip to content

Instantly share code, notes, and snippets.

@tim-br
Created August 3, 2015 23:24
Show Gist options
  • Save tim-br/cd51d5c91b2f7a347d46 to your computer and use it in GitHub Desktop.
Save tim-br/cd51d5c91b2f7a347d46 to your computer and use it in GitHub Desktop.
data MyVector a = XY a a deriving (Show)
xcord :: (Num a) => MyVector a -> a
xcord (XY a _) = a
ycord :: (Num a) => MyVector a -> a
ycord (XY _ a) = a
subVect :: (Num a) => MyVector a -> MyVector a -> MyVector a
subVect (XY x1 y1) (XY x2 y2) = XY (x1 - x2) (y1 - y2)
scaleVect :: (Num a) => MyVector a -> a -> MyVector a
scaleVect (XY x1 y1) n = XY (x1 * n) (y1 * n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment