{-# LANGUAGE QuantifiedConstraints #-} {-# LANGUAGE DerivingVia #-} -------------------------------------------------------------------------------- -- | -- Module : Data.Comp.Multi.HFunctor -- Copyright : (c) 2011 Patrick Bahr -- License : BSD3 -- Maintainer : Patrick Bahr -- Stability : experimental -- Portability : non-portable (GHC Extensions) -- -- This module defines higher-order functors (Johann, Ghani, POPL -- '08), i.e. endofunctors on the category of endofunctors. -- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- | -- Module : Data.Comp.Multi.HFoldable -- Copyright : (c) 2011 Patrick Bahr -- License : BSD3 -- Maintainer : Patrick Bahr -- Stability : experimental -- Portability : non-portable (GHC Extensions) -- -- This module defines higher-order foldable functors. -- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- | -- Module : Data.Comp.Multi.HTraversable -- Copyright : (c) 2011 Patrick Bahr -- License : BSD3 -- Maintainer : Patrick Bahr -- Stability : experimental -- Portability : non-portable (GHC Extensions) -- -- This module defines higher-order traversable functors. -- -------------------------------------------------------------------------------- module Data.Comp.Multi.Classes(HFunctor(..),HFoldable(..),HTraversable(..),HIdentity(..))where import Data.Kind import Data.Functor.Compose import Data.Functor.Const import Data.Maybe import Data.Monoid import Data.Functor.Classes import Data.Coerce import Data.Functor.Identity import Data.Foldable(Foldable(..)) import GHC.Generics -- | This class represents higher-order functors (Johann, Ghani, POPL -- '08) which are endofunctors on the category of endofunctors. type FTransformer = ((Type -> Type) -> Type -> Type) type HFunctor :: FTransformer -> Constraint class (forall f. Functor f => Functor (h f)) => HFunctor h where -- -- A higher-order functor @f@ maps every functor @g@ to a -- functor @f g@. -- -- @ffmap :: (Functor g) => (a -> b) -> f g a -> f g b@ -- -- We omit this, as it does not work for GADTs (see Johand and -- Ghani 2008). -- | A higher-order functor @f@ also maps a natural transformation -- @g :-> h@ to a natural transformation @f g :-> f h@ hfmap ::forall f g i. (f i -> g i) -> h f i -> h g i instance (Functor f) => HFunctor (Compose f) where hfmap f (Compose xs) = Compose (fmap f xs) type HIdentity :: FTransformer newtype HIdentity f a = MkHIdentity {getHIdentity::f a} deriving newtype (Eq,Ord,Show,Eq1,Ord1,Show1,Generic,Generic1,Functor,Foldable,Traversable)