-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Representable functors -- -- Representable functors @package representable-functors @version 2.2 -- | 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.Representable -- | A Functor f is Representable if tabulate -- and index witness an isomorphism to (->) x. -- --
--   tabulate . index = id
--   index . tabulate = id
--   tabulate . return f = return f
--   
class (Indexable f, Distributive f, Keyed f, Apply f, Applicative f, ZipWithKey f) => Representable f tabulate :: Representable f => (Key f -> a) -> f a -- | We extend lens across a representable functor, due to the preservation -- of limits. repLens :: Representable f => Lens a b -> Lens (f a) (f b) fmapRep :: Representable f => (a -> b) -> f a -> f b distributeRep :: (Representable f, Functor w) => w (f a) -> f (w a) mapWithKeyRep :: Representable f => (Key f -> a -> b) -> f a -> f b apRep :: Representable f => f (a -> b) -> f a -> f b pureRep :: Representable f => a -> f a bindRep :: Representable f => f a -> (a -> f b) -> f b bindWithKeyRep :: Representable f => f a -> (Key f -> a -> f b) -> f b zipWithRep :: Representable f => (a -> b -> c) -> f a -> f b -> f c zipWithKeyRep :: Representable f => (Key f -> a -> b -> c) -> f a -> f b -> f c askRep :: Representable f => f (Key f) localRep :: Representable f => (Key f -> Key f) -> f a -> f a duplicateRep :: (Representable f, Semigroup (Key f)) => f a -> f (f a) extendRep :: (Representable f, Semigroup (Key f)) => (f a -> b) -> f a -> f b extractRep :: (Indexable f, Monoid (Key f)) => f a -> a 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 Identity -- | Representable functors on Hask all monads, being isomorphic to a -- reader monad. module Control.Monad.Representable.Reader type Reader f = ReaderT f Identity runReader :: Indexable f => Reader f b -> Key f -> b newtype ReaderT f m b ReaderT :: f (m b) -> ReaderT f m b getReaderT :: ReaderT f m b -> f (m b) -- | Retrieves the monad environment. ask :: MonadReader r m => m r -- | Executes a computation in a modified environment. local :: MonadReader r m => forall a. (r -> r) -> m a -> m a 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, Semigroup (Key f), Semigroup (Key m), Monoid (Key f), Monoid (Key m)) => Comonad (ReaderT f m) instance (Representable f, Representable m) => ZipWithKey (ReaderT f m) instance (Representable f, Representable m) => Zip (ReaderT f m) instance (Representable f, Representable m, Semigroup (Key f), Semigroup (Key m)) => Extend (ReaderT f m) instance (TraversableWithKey1 f, TraversableWithKey1 m) => TraversableWithKey1 (ReaderT f m) instance (TraversableWithKey f, TraversableWithKey m) => TraversableWithKey (ReaderT f m) instance (Traversable1 f, Traversable1 m) => Traversable1 (ReaderT f m) instance (Traversable f, Traversable m) => Traversable (ReaderT f m) instance (FoldableWithKey1 f, FoldableWithKey1 m) => FoldableWithKey1 (ReaderT f m) instance (FoldableWithKey f, FoldableWithKey m) => FoldableWithKey (ReaderT f m) instance (Foldable1 f, Foldable1 m) => Foldable1 (ReaderT f m) instance (Foldable f, Foldable m) => Foldable (ReaderT f m) instance (Representable f, Representable m) => Representable (ReaderT f m) instance (Lookup f, Lookup m) => Lookup (ReaderT f m) instance (Adjustable f, Adjustable m) => Adjustable (ReaderT f m) instance (Indexable f, Indexable m) => Indexable (ReaderT f m) instance (Keyed f, Keyed m) => Keyed (ReaderT f m) instance (Representable f, Distributive m) => Distributive (ReaderT f m) instance Representable f => MonadTrans (ReaderT f) instance (Representable f, Monad m, Key f ~ e) => MonadReader e (ReaderT f m) 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 (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, Key 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 :: Indexable g => State g a -> Key g -> (a, Key g) -- | Evaluate a state computation with the given initial state and return -- the final value, discarding the final state. -- -- evalState :: Indexable g => State g a -> Key g -> a -- | Evaluate a state computation with the given initial state and return -- the final state, discarding the final value. -- -- execState :: Indexable g => State g a -> Key g -> Key g -- | Map both the return value and final state of a computation using the -- given function. -- -- mapState :: Functor g => ((a, Key g) -> (b, Key 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, Key g)) -> StateT g m a getStateT :: StateT g m a -> g (m (a, Key g)) stateT :: Representable g => (Key g -> m (a, Key g)) -> StateT g m a runStateT :: Indexable g => StateT g m a -> Key g -> m (a, Key g) -- | Evaluate a state computation with the given initial state and return -- the final value, discarding the final state. -- -- evalStateT :: (Indexable g, Monad m) => StateT g m a -> Key g -> m a -- | Evaluate a state computation with the given initial state and return -- the final state, discarding the final value. -- -- execStateT :: (Indexable g, Monad m) => StateT g m a -> Key g -> m (Key g) mapStateT :: Functor g => (m (a, Key g) -> n (b, Key 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, Key g) -> m (b, Key g)) -> m (a, Key g)) -> m (a, Key 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, Key g) -> m (b, Key g)) -> m (a, Key g)) -> m (a, Key g)) -> ((a -> StateT g m b) -> StateT g m a) -> StateT g m a -- | Return the state from the internals of the monad. get :: MonadState s m => m s -- | Gets specific component of the state, using a projection function -- supplied. gets :: MonadState s m => (s -> a) -> m a -- | Replace the state inside the monad. put :: MonadState s m => s -> m () -- | Monadic state transformer. -- -- Maps an old state to a new state inside a state monad. The old state -- is thrown away. -- --
--   Main> :t modify ((+1) :: Int -> Int)
--   modify (...) :: (MonadState Int a) => a ()
--   
-- -- This says that modify (+1) acts over any Monad that is a -- member of the MonadState class, with an Int state. modify :: MonadState s m => (s -> s) -> m () 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, Key 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 (Functor g, Indexable g, Bind m) => Bind (StateT g m) instance (Representable g, Functor m, Monad m) => Applicative (StateT g m) instance (Functor g, Indexable g, Bind m) => Apply (StateT g m) instance (Functor g, Functor m) => Functor (StateT g m) -- | A generalized Store comonad, parameterized by a Representable functor. -- The representation of that functor serves as the index of the store. module Control.Comonad.Representable.Store -- | A memoized store comonad parameterized by a representable functor -- g, where the representatation of g, Key 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 => (Key g -> a) -> Key g -> Store g a -- | Unwrap a state monad computation as a function. (The inverse of -- state.) runStore :: Indexable g => Store g a -> (Key g -> a, Key g) -- | A store transformer comonad parameterized by: -- -- data StoreT g w a StoreT :: (w (g a)) -> (Key g) -> StoreT g w a storeT :: (Functor w, Representable g) => w (Key g -> a) -> Key g -> StoreT g w a runStoreT :: (Functor w, Indexable g) => StoreT g w a -> (w (Key g -> a), Key g) pos :: ComonadStore s w => forall a. w a -> s peek :: ComonadStore s w => forall a. s -> w a -> a peeks :: ComonadStore s w => forall a. (s -> s) -> w a -> a seek :: ComonadStore s w => forall a. s -> w a -> w a seeks :: ComonadStore s w => forall a. (s -> s) -> w a -> w 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 Indexable 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 (Key g), Monoid (Key g), Representable g) => Applicative (StoreT g w) instance (Apply w, Semigroup (Key g), Representable g) => Apply (StoreT g w) instance (Functor w, Functor g) => Functor (StoreT g w) instance (Comonad w, Representable g, Key g ~ s) => ComonadStore s (StoreT g w) -- | Representable contravariant endofunctors over the category of Haskell -- types are isomorphic to (_ -> r) and resemble mappings to -- a fixed range. module Data.Functor.Corepresentable -- | Dual to Keyed. class Contravariant f => Valued f contramapWithValue :: Valued f => (b -> Either a (Value f)) -> f a -> f b -- | Dual to Indexed. class Coindexed f coindex :: Coindexed f => f a -> a -> Value f -- | A Functor f is Corepresentable if corep -- and coindex witness an isomorphism to (_ -> Value -- f). -- --
--   tabulate . index = id
--   index . tabulate = id
--   tabulate . return f = return f
--   
class (Coindexed f, Valued f) => Corepresentable f corep :: Corepresentable f => (a -> Value f) -> f a contramapDefault :: Corepresentable f => (a -> b) -> f b -> f a contramapWithValueDefault :: Corepresentable f => (b -> Either a (Value f)) -> f a -> f b instance (Coindexed f, Coindexed g) => Coindexed (Coproduct f g) instance (Corepresentable f, Corepresentable g) => Corepresentable (Product f g) instance (Coindexed f, Coindexed g) => Coindexed (Product f g) instance (Valued f, Valued g) => Valued (Product f g) instance Corepresentable Predicate instance Coindexed Predicate instance Valued Predicate instance Corepresentable (Op r) instance Coindexed (Op r) instance Valued (Op r)