-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Adjunctions and representable functors -- @package adjunctions @version 4.0 -- | Representable contravariant endofunctors over the category of Haskell -- types are isomorphic to (_ -> r) and resemble mappings to -- a fixed range. module Data.Functor.Contravariant.Rep -- | A Contravariant functor f is Representable if -- tabulate and index witness an isomorphism to (_ -- -> Rep f). -- --
--   tabulate . index ≡ id
--   index . tabulate ≡ id
--   
class Contravariant f => Representable f where type family Rep f :: * contramapWithRep f p = tabulate $ either (index p) id . f tabulate :: Representable f => (a -> Rep f) -> f a index :: Representable f => f a -> a -> Rep f contramapWithRep :: Representable f => (b -> Either a (Rep f)) -> f a -> f b contramapRep :: Representable f => (a -> b) -> f b -> f a instance (Representable f, Representable g) => Representable (Product f g) instance Representable Predicate instance Representable (Op r) instance (Representable f, Representable g) => Representable (Day f g) instance Representable Proxy -- |
--   Cont r ~ Contravariant.Adjoint (Op r) (Op r)
--   Conts r ~ Contravariant.AdjointT (Op r) (Op r)
--   ContsT r w m ~ Contravariant.AdjointT (Op (m r)) (Op (m r)) w
--   
module Control.Monad.Trans.Conts type Cont r = ContsT r Identity Identity cont :: ((a -> r) -> r) -> Cont r a runCont :: Cont r a -> (a -> r) -> r type Conts r w = ContsT r w Identity runConts :: Functor w => Conts r w a -> w (a -> r) -> r conts :: Functor w => (w (a -> r) -> r) -> Conts r w a newtype ContsT r w m a ContsT :: (w (a -> m r) -> m r) -> ContsT r w m a runContsT :: ContsT r w m a -> w (a -> m r) -> m r callCC :: Comonad w => ((a -> ContsT r w m b) -> ContsT r w m a) -> ContsT r w m a instance Comonad w => MonadTrans (ContsT r w) instance Comonad w => Monad (ContsT r w m) instance Comonad w => Applicative (ContsT r w m) instance Comonad w => Apply (ContsT r w m) instance Functor w => Functor (ContsT r w m) module Data.Functor.Contravariant.Adjunction -- | An adjunction from Hask^op to Hask -- --
--   Op (f a) b ~ Hask a (g b)
--   
-- --
--   rightAdjunct unit = id
--   leftAdjunct counit = id
--   
-- -- Any adjunction from Hask to Hask^op would indirectly -- permit unsafePerformIO, and therefore does not exist. class (Contravariant f, Representable g) => Adjunction f g | f -> g, g -> f where unit = leftAdjunct id counit = rightAdjunct id leftAdjunct f = contramap f . unit rightAdjunct f = contramap f . counit unit :: Adjunction f g => a -> g (f a) counit :: Adjunction f g => a -> f (g a) leftAdjunct :: Adjunction f g => (b -> f a) -> a -> g b rightAdjunct :: Adjunction f g => (a -> g b) -> b -> f a -- | Represent a Contravariant functor that has a left adjoint contrarepAdjunction :: Adjunction f g => (a -> f ()) -> g a coindexAdjunction :: Adjunction f g => g a -> a -> f () instance Adjunction Predicate Predicate instance Adjunction (Op r) (Op r) -- | Uses a contravariant adjunction: -- -- f -| g : Hask^op -> Hask -- -- to build a Comonad to Monad transformer. Sadly, the dual -- construction, which builds a Comonad out of a Monad, is -- uninhabited, because any Adjunction of the form -- --
--   f -| g : Hask -> Hask^op
--   
-- -- would trivially admit unsafePerformIO. module Control.Monad.Trans.Contravariant.Adjoint type Adjoint f g = AdjointT f g Identity runAdjoint :: Contravariant g => Adjoint f g a -> g (f a) adjoint :: Contravariant g => g (f a) -> Adjoint f g a newtype AdjointT f g w a AdjointT :: g (w (f a)) -> AdjointT f g w a runAdjointT :: AdjointT f g w a -> g (w (f a)) instance (Adjunction f g, Comonad w) => Monad (AdjointT f g w) instance (Adjunction f g, Comonad w) => Applicative (AdjointT f g w) instance (Adjunction f g, Functor w) => Functor (AdjointT f g w) -- | Representable endofunctors over the category of Haskell types are -- isomorphic to the reader monad and so inherit a very large number of -- properties for free. module Data.Functor.Rep -- | A Functor f is Representable if tabulate -- and index witness an isomorphism to (->) x. -- -- Every Distributive Functor is actually -- Representable. -- -- Every Representable Functor from Hask to Hask is a right -- adjoint. -- --
--   tabulate . index    ≡ id
--   index . tabulate    ≡ id
--   tabulate . return f ≡ return f
--   
class Distributive f => Representable f where type family Rep f :: * tabulate :: Representable f => (Rep f -> a) -> f a index :: Representable f => f a -> Rep f -> a newtype Co f a Co :: f a -> Co f a unCo :: Co f a -> f a fmapRep :: Representable f => (a -> b) -> f a -> f b distributeRep :: (Representable f, Functor w) => w (f a) -> f (w a) apRep :: Representable f => f (a -> b) -> f a -> f b pureRep :: Representable f => a -> f a liftR2 :: Representable f => (a -> b -> c) -> f a -> f b -> f c liftR3 :: Representable f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d bindRep :: Representable f => f a -> (a -> f b) -> f b askRep :: Representable f => f (Rep f) localRep :: Representable f => (Rep f -> Rep f) -> f a -> f a duplicatedRep :: (Representable f, Semigroup (Rep f)) => f a -> f (f a) extendedRep :: (Representable f, Semigroup (Rep f)) => (f a -> b) -> f a -> f b duplicateRep :: (Representable f, Monoid (Rep f)) => f a -> f (f a) extendRep :: (Representable f, Monoid (Rep f)) => (f a -> b) -> f a -> f b extractRep :: (Representable f, Monoid (Rep f)) => f a -> a instance Functor f => Functor (Co f) instance ComonadTrans Co instance (Representable f, Monoid (Rep f)) => Comonad (Co f) instance (Representable f, Semigroup (Rep f)) => Extend (Co f) instance (Representable f, Rep f ~ a) => MonadReader a (Co f) instance Representable f => Monad (Co f) instance Representable f => Bind (Co f) instance Representable f => Distributive (Co f) instance Representable f => Applicative (Co f) instance Representable f => Apply (Co f) instance Representable f => Representable (Co f) instance Representable f => Representable (Cofree f) instance (Representable f, Representable g) => Representable (Product f g) instance Representable w => Representable (TracedT s w) instance (Representable f, Representable g) => Representable (Compose f g) instance Representable m => Representable (ReaderT e m) instance Representable ((->) e) instance Representable m => Representable (IdentityT m) instance Representable (Tagged t) instance Representable Identity instance Representable Proxy module Data.Functor.Adjunction -- | An adjunction between Hask and Hask. -- -- Minimal definition: both unit and counit or both -- leftAdjunct and rightAdjunct, subject to the constraints -- imposed by the default definitions that the following laws should -- hold. -- --
--   unit = leftAdjunct id
--   counit = rightAdjunct id
--   leftAdjunct f = fmap f . unit
--   rightAdjunct f = counit . fmap f
--   
-- -- Any implementation is required to ensure that leftAdjunct and -- rightAdjunct witness an isomorphism from Nat (f a, b) -- to Nat (a, g b) -- --
--   rightAdjunct unit = id
--   leftAdjunct counit = id
--   
class (Functor f, Representable u) => Adjunction f u | f -> u, u -> f where unit = leftAdjunct id counit = rightAdjunct id leftAdjunct f = fmap f . unit rightAdjunct f = counit . fmap f unit :: Adjunction f u => a -> u (f a) counit :: Adjunction f u => f (u a) -> a leftAdjunct :: Adjunction f u => (f a -> b) -> a -> u b rightAdjunct :: Adjunction f u => (a -> u b) -> f a -> b -- | Every right adjoint is representable by its left adjoint applied to a -- unit element -- -- Use this definition and the primitives in Data.Functor.Representable -- to meet the requirements of the superclasses of Representable. tabulateAdjunction :: Adjunction f u => (f () -> b) -> u b -- | This definition admits a default definition for the index -- method of 'Index", one of the superclasses of Representable. indexAdjunction :: Adjunction f u => u b -> f a -> b zapWithAdjunction :: Adjunction f u => (a -> b -> c) -> u a -> f b -> c -- | A right adjoint functor admits an intrinsic notion of zipping zipR :: Adjunction f u => (u a, u b) -> u (a, b) -- | Every functor in Haskell permits unzipping unzipR :: Functor u => u (a, b) -> (u a, u b) -- | A left adjoint must be inhabited, or we can derive bottom. unabsurdL :: Adjunction f u => f Void -> Void absurdL :: Void -> f Void -- | And a left adjoint must be inhabited by exactly one element cozipL :: Adjunction f u => f (Either a b) -> Either (f a) (f b) -- | Every functor in Haskell permits uncozipping uncozipL :: Functor f => Either (f a) (f b) -> f (Either a b) extractL :: Adjunction f u => f a -> a duplicateL :: Adjunction f u => f a -> f (f a) splitL :: Adjunction f u => f a -> (a, f ()) unsplitL :: Functor f => a -> f () -> f a instance Adjunction f u => Adjunction (Free f) (Cofree u) instance (Adjunction f g, Adjunction f' g') => Adjunction (Coproduct f f') (Product g g') instance (Adjunction f g, Adjunction f' g') => Adjunction (Compose f' f) (Compose g g') instance Adjunction m w => Adjunction (WriterT s m) (TracedT s w) instance Adjunction w m => Adjunction (EnvT e w) (ReaderT e m) instance Adjunction f g => Adjunction (IdentityT f) (IdentityT g) instance Adjunction Identity Identity instance Adjunction ((,) e) ((->) e) module Control.Comonad.Trans.Adjoint type Adjoint f g = AdjointT f g Identity runAdjoint :: Functor f => Adjoint f g a -> f (g a) adjoint :: Functor f => f (g a) -> Adjoint f g a newtype AdjointT f g w a AdjointT :: f (w (g a)) -> AdjointT f g w a runAdjointT :: AdjointT f g w a -> f (w (g a)) instance (Adjunction f g, Distributive g) => ComonadTrans (AdjointT f g) instance (Adjunction f g, Comonad w) => Comonad (AdjointT f g w) instance (Adjunction f g, Extend w) => Extend (AdjointT f g w) instance (Adjunction f g, Functor w) => Functor (AdjointT f g w) module Control.Monad.Trans.Adjoint type Adjoint f g = AdjointT f g Identity runAdjoint :: Functor g => Adjoint f g a -> g (f a) adjoint :: Functor g => g (f a) -> Adjoint f g a newtype AdjointT f g m a AdjointT :: g (m (f a)) -> AdjointT f g m a runAdjointT :: AdjointT f g m a -> g (m (f a)) instance (Adjunction f g, Traversable f) => MonadTrans (AdjointT f g) instance (Adjunction f g, Monad m) => Monad (AdjointT f g m) instance (Adjunction f g, Monad m) => Applicative (AdjointT f g m) instance (Adjunction f g, Monad m) => Functor (AdjointT f g m) -- | Representable functors on Hask are all monads, because they are -- isomorphic to a Reader monad. module Control.Monad.Representable.Reader type Reader f = ReaderT f Identity runReader :: Representable f => Reader f b -> Rep f -> b newtype ReaderT f m b ReaderT :: f (m b) -> ReaderT f m b getReaderT :: ReaderT f m b -> f (m b) readerT :: Representable f => (Rep f -> m b) -> ReaderT f m b runReaderT :: Representable f => ReaderT f m b -> Rep f -> m b -- | See examples in Control.Monad.Reader. Note, the partially -- applied function type (->) r is a simple reader monad. See -- the instance declaration below. class Monad m => MonadReader r (m :: * -> *) | m -> r ask :: MonadReader r m => m r local :: MonadReader r m => (r -> r) -> m a -> m a reader :: MonadReader r m => (r -> a) -> m a instance (Traversable1 f, Traversable1 m) => Traversable1 (ReaderT f m) instance (Traversable f, Traversable m) => Traversable (ReaderT f m) instance (Foldable1 f, Foldable1 m) => Foldable1 (ReaderT f m) instance (Foldable f, Foldable m) => Foldable (ReaderT f m) instance (Representable f, MonadWriter w m) => MonadWriter w (ReaderT f m) instance (Representable f, MonadIO m) => MonadIO (ReaderT f m) instance (Representable f, Representable m, Monoid (Rep f), Monoid (Rep m)) => Comonad (ReaderT f m) instance (Representable f, Representable m, Semigroup (Rep f), Semigroup (Rep m)) => Extend (ReaderT f m) instance (Representable f, Distributive m) => Distributive (ReaderT f m) instance Representable f => MonadTrans (ReaderT f) instance (Representable f, Monad m) => Monad (ReaderT f m) instance (Representable f, Bind m) => Bind (ReaderT f m) instance (Representable f, Applicative m) => Applicative (ReaderT f m) instance (Representable f, Apply m) => Apply (ReaderT f m) instance (Representable f, Representable m) => Representable (ReaderT f m) instance (Functor f, Functor m) => Functor (ReaderT f m) -- | A generalized State monad, parameterized by a Representable functor. -- The representation of that functor serves as the state. module Control.Monad.Representable.State -- | A memoized state monad parameterized by a representable functor -- g, where the representatation of g, Rep g -- is the state to carry. -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as -- the initial state of the second. type State g = StateT g Identity -- | Unwrap a state monad computation as a function. (The inverse of -- state.) runState :: Representable g => State g a -> Rep g -> (a, Rep g) -- | Evaluate a state computation with the given initial state and return -- the final value, discarding the final state. -- -- evalState :: Representable g => State g a -> Rep g -> a -- | Evaluate a state computation with the given initial state and return -- the final state, discarding the final value. -- -- execState :: Representable g => State g a -> Rep g -> Rep g -- | Map both the return value and final state of a computation using the -- given function. -- -- mapState :: Functor g => ((a, Rep g) -> (b, Rep g)) -> State g a -> State g b -- | A state transformer monad parameterized by: -- -- -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as -- the initial state of the second. newtype StateT g m a StateT :: g (m (a, Rep g)) -> StateT g m a getStateT :: StateT g m a -> g (m (a, Rep g)) stateT :: Representable g => (Rep g -> m (a, Rep g)) -> StateT g m a runStateT :: Representable g => StateT g m a -> Rep g -> m (a, Rep g) -- | Evaluate a state computation with the given initial state and return -- the final value, discarding the final state. -- -- evalStateT :: (Representable g, Monad m) => StateT g m a -> Rep g -> m a -- | Evaluate a state computation with the given initial state and return -- the final state, discarding the final value. -- -- execStateT :: (Representable g, Monad m) => StateT g m a -> Rep g -> m (Rep g) mapStateT :: Functor g => (m (a, Rep g) -> n (b, Rep g)) -> StateT g m a -> StateT g n b -- | Uniform lifting of a callCC operation to the new monad. This -- version rolls back to the original state on entering the continuation. liftCallCC :: Representable g => ((((a, Rep g) -> m (b, Rep g)) -> m (a, Rep g)) -> m (a, Rep g)) -> ((a -> StateT g m b) -> StateT g m a) -> StateT g m a -- | In-situ lifting of a callCC operation to the new monad. This -- version uses the current state on entering the continuation. It does -- not satisfy the laws of a monad transformer. liftCallCC' :: Representable g => ((((a, Rep g) -> m (b, Rep g)) -> m (a, Rep g)) -> m (a, Rep g)) -> ((a -> StateT g m b) -> StateT g m a) -> StateT g m a -- | Minimal definition is either both of get and put or -- just state class Monad m => MonadState s (m :: * -> *) | m -> s get :: MonadState s m => m s put :: MonadState s m => s -> m () state :: MonadState s m => (s -> (a, s)) -> m a instance (Functor f, Representable g, MonadFree f m) => MonadFree f (StateT g m) instance (Representable g, MonadCont m) => MonadCont (StateT g m) instance (Representable g, MonadWriter w m) => MonadWriter w (StateT g m) instance (Representable g, MonadReader e m) => MonadReader e (StateT g m) instance (Representable g, Monad m, Rep g ~ s) => MonadState s (StateT g m) instance Representable f => MonadTrans (StateT f) instance Representable f => BindTrans (StateT f) instance (Representable g, Monad m) => Monad (StateT g m) instance (Representable g, Bind m) => Bind (StateT g m) instance (Representable g, Functor m, Monad m) => Applicative (StateT g m) instance (Representable g, Bind m) => Apply (StateT g m) instance (Functor g, Functor m) => Functor (StateT g m) -- | This is a generalized Store Comonad, parameterized by a -- Representable Functor. The representation of that -- Functor serves as the index of the store. -- -- This can be useful if the representable functor serves to memoize its -- contents and will be inspected often. module Control.Comonad.Representable.Store -- | A memoized store comonad parameterized by a representable functor -- g, where the representatation of g, Rep g -- is the index of the store. type Store g = StoreT g Identity -- | Construct a store comonad computation from a function and a current -- index. (The inverse of runStore.) store :: Representable g => (Rep g -> a) -> Rep g -> Store g a -- | Unwrap a state monad computation as a function. (The inverse of -- state.) runStore :: Representable g => Store g a -> (Rep g -> a, Rep g) -- | A store transformer comonad parameterized by: -- -- data StoreT g w a StoreT :: (w (g a)) -> (Rep g) -> StoreT g w a storeT :: (Functor w, Representable g) => w (Rep g -> a) -> Rep g -> StoreT g w a runStoreT :: (Functor w, Representable g) => StoreT g w a -> (w (Rep g -> a), Rep g) class Comonad w => ComonadStore s (w :: * -> *) | w -> s pos :: ComonadStore s w => w a -> s peek :: ComonadStore s w => s -> w a -> a peeks :: ComonadStore s w => (s -> s) -> w a -> a seek :: ComonadStore s w => s -> w a -> w a seeks :: ComonadStore s w => (s -> s) -> w a -> w a experiment :: (ComonadStore s w, Functor f) => (s -> f s) -> w a -> f a instance (Representable g, ComonadCofree f w) => ComonadCofree f (StoreT g w) instance (ComonadEnv m w, Representable g) => ComonadEnv m (StoreT g w) instance (ComonadTraced m w, Representable g) => ComonadTraced m (StoreT g w) instance ComonadHoist (StoreT g) instance Representable g => ComonadTrans (StoreT g) instance (Comonad w, Representable g) => Comonad (StoreT g w) instance (Extend w, Representable g) => Extend (StoreT g w) instance (Applicative w, Semigroup (Rep g), Monoid (Rep g), Representable g) => Applicative (StoreT g w) instance (ComonadApply w, Semigroup (Rep g), Representable g) => ComonadApply (StoreT g w) instance (Apply w, Semigroup (Rep g), Representable g) => Apply (StoreT g w) instance (Functor w, Functor g) => Functor (StoreT g w) instance (Comonad w, Representable g, Rep g ~ s) => ComonadStore s (StoreT g w)