Last active
February 21, 2019 21:16
-
-
Save v0d1ch/8e3fd00f3311081f1ad87e403244c586 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
data Vec3 a = Vec3 a a a deriving (Eq, Show) | |
instance Functor Vec3 where | |
fmap f (Vec3 a b c) = Vec3 (f a) (f b) (f c) | |
instance Applicative Vec3 where | |
pure a = Vec3 a a a | |
(Vec3 f f' f'') <*> (Vec3 a b c) = Vec3 (f a) (f' b) (f'' c) | |
instance Foldable Vec3 where | |
foldr :: (a -> b -> b) -> b -> Vec3 a -> b | |
foldr f d (Vec3 a b c) = f a (f b (f c d)) | |
instance Traversable Vec3 where | |
traverse :: Applicative f => (a -> f b) -> Vec3 a -> f (Vec3 b) | |
traverse f (Vec3 a b c) = Vec3 <$> f a <*> f b <*> f c | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment