Last active
August 29, 2015 14:23
-
-
Save fritz0705/9cb6d6ed21e06ee4890c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newtype Vector2 a = Vector2 (a, a) | |
instance Eq a => Eq (Vector2 a) where | |
Vector2 x == Vector2 y = x == y | |
instance Functor Vector2 where | |
fmap f (Vector2 (a, b)) = Vector2 (f a, f b) | |
instance Applicative Vector2 where | |
pure x = Vector2 (x, x) | |
Vector2 (f, g) <*> Vector2 (x, y) = Vector2 (f x, g y) | |
instance Foldable Vector2 where | |
foldr f z (Vector2 (x, y)) = f y . f a $ z | |
instance (Eq a, Ord a) => Ord (Vector2 a) where | |
compare x y = fold $ compare <$> x <*> y | |
instance Num a => Num (Vector2 a) where | |
Vector2 (a, b) + Vector2 (c, d) = Vector2 (a + c, b + d) | |
abs = (abs <$>) | |
signum = (signum <$>) | |
fromInteger = undefined -- Is there a sensible instance? | |
(*) = undefined -- There is no sensible instance for a commutative-associative multiplication *: V x V -> V |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment