Skip to content

Instantly share code, notes, and snippets.

@v0d1ch
Last active February 21, 2019 21:16
Show Gist options
  • Save v0d1ch/8e3fd00f3311081f1ad87e403244c586 to your computer and use it in GitHub Desktop.
Save v0d1ch/8e3fd00f3311081f1ad87e403244c586 to your computer and use it in GitHub Desktop.
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