-- 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: -- --
evalStateT m s = liftM fst -- (runStateT m s)
execStateT m s = liftM snd -- (runStateT m s)
-- 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: -- --
-- 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)