module Data.Functor.Contravariant.Compose
( Compose(..)
, ComposeFC(..)
, ComposeCF(..)
) where
import Data.Functor.Contravariant
newtype Compose f g a = Compose { getCompose :: f (g a) }
instance (Contravariant f, Contravariant g) => Functor (Compose f g) where
fmap f (Compose x) = Compose (contramap (contramap f) x)
newtype ComposeFC f g a = ComposeFC { getComposeFC :: f (g a) }
instance (Functor f, Contravariant g) => Contravariant (ComposeFC f g) where
contramap f (ComposeFC x) = ComposeFC (fmap (contramap f) x)
instance (Functor f, Functor g) => Functor (ComposeFC f g) where
fmap f (ComposeFC x) = ComposeFC (fmap (fmap f) x)
newtype ComposeCF f g a = ComposeCF { getComposeCF :: f (g a) }
instance (Contravariant f, Functor g) => Contravariant (ComposeCF f g) where
contramap f (ComposeCF x) = ComposeCF (contramap (fmap f) x)
instance (Functor f, Functor g) => Functor (ComposeCF f g) where
fmap f (ComposeCF x) = ComposeCF (fmap (fmap f) x)