module Pandora.Pattern.Functor.Covariant (Covariant (..)) where
import Pandora.Core.Morphism (fix, (.), ($), (!), (?))
infixl 4 <$>, <$, $>
class Covariant (t :: * -> *) where
{-# MINIMAL (<$>) #-}
(<$>) :: (a -> b) -> t a -> t b
comap :: (a -> b) -> t a -> t b
comap f x = f <$> x
(<$) :: a -> t b -> t a
(<$) = comap . (!)
($>) :: t a -> b -> t b
($>) = (?) (<$)
void :: t a -> t ()
void x = () <$ x
loeb :: t (t a -> a) -> t a
loeb tt = fix $ \f -> ($ f) <$> tt
(<$$>) :: Covariant u => (a -> b) -> t (u a) -> t (u b)
(<$$>) = (<$>) . (<$>)
(<$$$>) :: (Covariant u, Covariant v) => (a -> b) -> t (u (v a)) -> t (u (v b))
(<$$$>) = (<$>) . (<$>) . (<$>)
(<$$$$>) :: (Covariant u, Covariant v, Covariant w) => (a -> b) -> t (u (v ( w a))) -> t (u (v (w b)))
(<$$$$>) = (<$>) . (<$>) . (<$>) . (<$>)
instance Covariant ((->) a) where
(<$>) = (.)