Created
May 29, 2018 15:23
-
-
Save emilypi/c9190985f9a71702db46ca53c8091840 to your computer and use it in GitHub Desktop.
Functor Results
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
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE FunctionalDependencies #-} | |
module RB where | |
import Data.Functor.Contravariant | |
newtype O f g e = Comp { deComp :: f (g e) } | |
newtype Square f a = Square { unSquare :: f (f a) } | |
instance Contravariant f => Functor (Square f) where | |
fmap f = Square . contramap (contramap f) . unSquare | |
instance (Contravariant f, Contravariant g) => Functor (O f g) where | |
fmap f = Comp . contramap (contramap f) . deComp | |
class Coyo f a where | |
coyoneda :: (b -> a) -> f a -> f b | |
class Yon f a where | |
yoneda :: (a -> b) -> f b | |
instance (Functor f, Contravariant g) => Coyo (O f g) (g a) where | |
coyoneda f = Comp . fmap (contramap f) . deComp | |
instance (Contravariant f, Functor g) => Coyo (O f g) (g a) where | |
coyoneda f = Comp . contramap (fmap f) . deComp | |
instance (Functor f, Functor g) => Yon (O f g) (g a) where | |
yoneda f = Comp . fmap (fmap f) . deComp | |
instance (Contravariant f, Contravariant g) => Yon (O f g) (g a) where | |
yoneda f = Comp . contramap (contramap f) . deComp | |
newtype Product f g a = Product (f a, g a) | |
newtype Coproduct f g a = Coproduct (Either (f a) (g a)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment