module Control.Functor.HigherOrder
( HFunctor(..)
, HPointed(..)
, HCopointed(..)
, AlgH
, CoAlgH
, FixH(..)
, LowerH(..)
) where
import Control.Functor.Pointed
import Control.Functor.Extras
type AlgH f g = Natural (f g) g
type CoAlgH f g = Natural g (f g)
class HFunctor f where
ffmap :: Functor g => (a -> b) -> f g a -> f g b
hfmap :: Natural g h -> Natural (f g) (f h)
newtype FixH f a = InH { outH :: f (FixH f) a }
class HFunctor m => HPointed m where
hreturn :: Functor f => Natural f (m f)
class HFunctor w => HCopointed w where
hextract :: Functor f => Natural (w f) f
newtype LowerH
(h :: (* -> *) -> * -> *)
(f :: * -> *)
(a :: *) = LowerH { liftH :: h f a }
instance (HFunctor h, Functor f) => Functor (LowerH h f) where
fmap f = LowerH . ffmap f . liftH
instance (HPointed h, Pointed f) => Pointed (LowerH h f) where
point = LowerH . hreturn . point
instance (HCopointed h, Copointed f) => Copointed (LowerH h f) where
extract = extract . hextract . liftH