packages feed

representable-functors 0.5.0 → 1.8.0

raw patch · 5 files changed

+493/−141 lines, 5 filesdep +comonads-fddep +data-lensdep +freedep ~comonad-transformersdep ~keys

Dependencies added: comonads-fd, data-lens, free

Dependency ranges changed: comonad-transformers, keys

Files

+ Control/Comonad/Representable/Store.hs view
@@ -0,0 +1,116 @@+{-# LANGUAGE TypeFamilies+           , FlexibleContexts+           , FlexibleInstances+           , MultiParamTypeClasses+           , UndecidableInstances #-}+----------------------------------------------------------------------+-- |+-- Module      :  Control.Comonad.Representable.Store+-- Copyright   :  (c) Edward Kmett & Sjoerd Visscher 2011+-- License     :  BSD3+-- +-- Maintainer  :  ekmett@gmail.com+-- Stability   :  experimental+-- +-- 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+   ( Store+   , store+   , runStore+   , StoreT(..)+   , storeT+   , runStoreT+   , pos+   , peek+   , peeks+   , seek+   , seeks+   ) where++import Control.Comonad+import Control.Applicative+import Data.Key+import Data.Functor.Apply+import Data.Monoid+import Control.Comonad.Hoist.Class+import Control.Comonad.Env.Class+import Control.Comonad.Traced.Class+import Control.Comonad.Cofree.Class+import Control.Comonad.Trans.Class+import Control.Comonad.Store.Class+import Control.Monad.Identity+import Data.Functor.Representable++-- | 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)  -- ^ computation+      -> Key g         -- ^ index+      -> Store g a+store = storeT . Identity++-- | Unwrap a state monad computation as a function.+-- (The inverse of 'state'.)+runStore :: Indexable g +         => Store g a           -- ^ a store to access+         -> (Key g -> a, Key g) -- ^ initial state+runStore (StoreT (Identity ga) k) = (index ga, k)++-- ---------------------------------------------------------------------------+-- | A store transformer comonad parameterized by:+--+--   * @g@ - A representable functor used to memoize results for an index @Key g@+--+--   * @w@ - The inner comonad.+data StoreT g w a = StoreT (w (g a)) (Key g) ++storeT :: (Functor w, Representable g) => w (Key g -> a) -> Key g -> StoreT g w a +storeT = StoreT . fmap tabulate++runStoreT :: (Functor w, Indexable g) => StoreT g w a -> (w (Key g -> a), Key g)+runStoreT (StoreT w s) = (index <$> w, s)++instance (Comonad w, Representable g, Key g ~ s) => ComonadStore s (StoreT g w) where+  pos (StoreT _ s) = s+  peek s (StoreT w _) = extract w `index` s+  peeks f (StoreT w s) = extract w `index` f s+  seek s (StoreT w _) = StoreT w s+  seeks f (StoreT w s) = StoreT w (f s)++instance (Functor w, Functor g) => Functor (StoreT g w) where+  fmap f (StoreT w s) = StoreT (fmap (fmap f) w) s++instance (Apply w, Semigroup (Key g), Representable g) => Apply (StoreT g w) where+  StoreT ff m <.> StoreT fa n = StoreT ((<*>) <$> ff <.> fa) (m <> n)++instance (Applicative w, Semigroup (Key g), Monoid (Key g), Representable g) => Applicative (StoreT g w) where+  pure a = StoreT (pure (pure a)) mempty+  StoreT ff m <*> StoreT fa n = StoreT ((<*>) <$> ff <*> fa) (m `mappend` n)++instance (Extend w, Representable g) => Extend (StoreT g w) where+  duplicate (StoreT wf s) = StoreT (extend (tabulate . StoreT) wf) s++instance (Comonad w, Representable g) => Comonad (StoreT g w) where+  extract (StoreT wf s) = index (extract wf) s++instance Indexable g => ComonadTrans (StoreT g) where+  lower (StoreT w s) = fmap (`index` s) w++instance ComonadHoist (StoreT g) where+  cohoist (StoreT w s) = StoreT (Identity (extract w)) s++instance (ComonadTraced m w, Representable g) => ComonadTraced m (StoreT g w) where+  trace m = trace m . lower++instance (ComonadEnv m w, Representable g) => ComonadEnv m (StoreT g w) where +  ask = ask . lower++instance (Representable g, ComonadCofree f w) => ComonadCofree f (StoreT g w) where+  unwrap (StoreT w s) = fmap (`StoreT` s) (unwrap w)
− Control/Monad/Representable.hs
@@ -1,136 +0,0 @@-{-# LANGUAGE GADTs, TypeFamilies, TypeOperators, CPP, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, UndecidableInstances, TypeSynonymInstances #-}-{-# OPTIONS_GHC -fenable-rewrite-rules -fno-warn-orphans #-}-------------------------------------------------------------------------- |--- Module      :  Control.Monad.Representable--- Copyright   :  (c) Edward Kmett 2011,---                (c) Conal Elliott 2008--- License     :  BSD3--- --- Maintainer  :  ekmett@gmail.com--- Stability   :  experimental--- --- Representable functors on Hask all monads, being isomorphic to--- a reader monad.-------------------------------------------------------------------------module Control.Monad.Representable-  ( -  -- * Representable functor monad-    Rep, rep, runRep-  -- * Monad Transformer-  , RepT(..)-  , module Data.Functor.Representable-  ) where--import Control.Applicative-import Control.Comonad-import Control.Monad.Reader-import Control.Monad.Writer.Class as Writer-import Control.Monad.Trans.Class-import Control.Monad.IO.Class-import Data.Distributive-import Data.Key-import Data.Functor.Bind-import Data.Functor.Identity-import Data.Functor.Representable-import Data.Foldable-import Data.Monoid-import Data.Traversable-import Data.Semigroup.Foldable-import Data.Semigroup.Traversable-import Prelude hiding (lookup)--type Rep f = RepT f Identity--rep :: Functor f => f b -> Rep f b-rep = RepT . fmap Identity--runRep :: Functor f => Rep f b -> f b-runRep = fmap runIdentity . runRepT---- * This 'tabulateresentable monad transformer' transforms any monad @m@ with a 'Representable' 'Monad'.---   This monad in turn is also tabulateresentable if @m@ is 'Representable'.-newtype RepT f m b = RepT { runRepT :: f (m b) }--type instance Key (RepT f m) = (Key f, Key m)--instance (Functor f, Functor m) => Functor (RepT f m) where-  fmap f = RepT . fmap (fmap f) . runRepT--instance (Representable f, Apply m) => Apply (RepT f m) where-  RepT ff <.> RepT fa = RepT ((<.>) <$> ff <.> fa)--instance (Representable f, Applicative m) => Applicative (RepT f m) where-  pure = RepT . pure . pure -  RepT ff <*> RepT fa = RepT ((<*>) <$> ff <*> fa)--instance (Representable f, Bind m) => Bind (RepT f m) where-  RepT fm >>- f = RepT $ tabulate (\a -> index fm a >>- flip index a . runRepT . f)--instance (Representable f, Monad m) => Monad (RepT f m) where-  return = RepT . pure . return-  RepT fm >>= f = RepT $ tabulate (\a -> index fm a >>= flip index a . runRepT . f)---- instance (Representable f, Monad m) => MonadReader (Key f) (RepT f m) where ask = RepT (tabulate return)--instance Representable f => MonadTrans (RepT f) where-  lift = RepT . pure --instance (Representable f, Distributive m) => Distributive (RepT f m) where-  distribute = RepT . fmap distribute . collect runRepT--instance (Keyed f, Keyed m) => Keyed (RepT f m) where-  mapWithKey f = RepT . mapWithKey (\k -> mapWithKey (f . (,) k)) . runRepT--instance (Indexable f, Indexable m) => Indexable (RepT f m) where-  index = uncurry . fmap index . index . runRepT--instance (Adjustable f, Adjustable m) => Adjustable (RepT f m) where-  adjust f (kf,km) = RepT . adjust (adjust f km) kf . runRepT--instance (Lookup f, Lookup m) => Lookup (RepT f m) where-  lookup (k,k') (RepT fm) = lookup k fm >>= lookup k'--instance (Representable f, Representable m) => Representable (RepT f m) where-  tabulate = RepT . tabulate . fmap tabulate . curry-  -instance (Foldable f, Foldable m) => Foldable (RepT f m) where-  foldMap f = foldMap (foldMap f) . runRepT--instance (Foldable1 f, Foldable1 m) => Foldable1 (RepT f m) where-  foldMap1 f = foldMap1 (foldMap1 f) . runRepT--instance (FoldableWithKey f, FoldableWithKey m) => FoldableWithKey (RepT f m) where-  foldMapWithKey f = foldMapWithKey (\k -> foldMapWithKey (f . (,) k)) . runRepT--instance (FoldableWithKey1 f, FoldableWithKey1 m) => FoldableWithKey1 (RepT f m) where-  foldMapWithKey1 f = foldMapWithKey1 (\k -> foldMapWithKey1 (f . (,) k)) . runRepT --instance (Traversable f, Traversable m) => Traversable (RepT f m) where-  traverse f = fmap RepT . traverse (traverse f) . runRepT--instance (Traversable1 f, Traversable1 m) => Traversable1 (RepT f m) where-  traverse1 f = fmap RepT . traverse1 (traverse1 f) . runRepT--instance (TraversableWithKey f, TraversableWithKey m) => TraversableWithKey (RepT f m) where-  traverseWithKey f = fmap RepT . traverseWithKey (\k -> traverseWithKey (f . (,) k)) . runRepT--instance (TraversableWithKey1 f, TraversableWithKey1 m) => TraversableWithKey1 (RepT f m) where-  traverseWithKey1 f = fmap RepT . traverseWithKey1 (\k -> traverseWithKey1 (f . (,) k)) . runRepT--instance (Representable f, Representable m, Semigroup (Key f), Semigroup (Key m)) => Extend (RepT f m) where-  extend = extendRep-  duplicate = duplicateRep--instance (Representable f, Representable m, Semigroup (Key f), Semigroup (Key m), Monoid (Key f), Monoid (Key m)) => Comonad (RepT f m) where-  extract = extractRep--instance (Representable f, MonadIO m) => MonadIO (RepT f m) where-  liftIO = lift . liftIO --instance (Representable f, MonadWriter w m) => MonadWriter w (RepT f m) where-  tell = lift . tell-  listen (RepT m) = RepT $ tabulate $ Writer.listen . index m-  pass (RepT m) = RepT $ tabulate $ Writer.pass . index m-
+ Control/Monad/Representable/Reader.hs view
@@ -0,0 +1,146 @@+{-# LANGUAGE GADTs, TypeFamilies, TypeOperators, CPP, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, UndecidableInstances, TypeSynonymInstances #-}+{-# OPTIONS_GHC -fenable-rewrite-rules -fno-warn-orphans #-}+----------------------------------------------------------------------+-- |+-- Module      :  Control.Monad.Representable.Reader+-- Copyright   :  (c) Edward Kmett 2011,+--                (c) Conal Elliott 2008+-- License     :  BSD3+-- +-- Maintainer  :  ekmett@gmail.com+-- Stability   :  experimental+-- +-- Representable functors on Hask all monads, being isomorphic to+-- a reader monad.+----------------------------------------------------------------------++module Control.Monad.Representable.Reader+  ( +  -- * Representable functor monad+    Reader, reader, runReader+  -- * Monad Transformer+  , ReaderT(..)+  , ask+  , local+  , module Data.Functor.Representable+  ) where++import Control.Applicative+import Control.Comonad+import Control.Monad.Reader.Class+import Control.Monad.Writer.Class as Writer+import Control.Monad.Trans.Class+import Control.Monad.IO.Class+import Data.Distributive+import Data.Key+import Data.Functor.Bind+import Data.Functor.Identity+import Data.Functor.Representable+import Data.Foldable+import Data.Monoid+import Data.Traversable+import Data.Semigroup.Foldable+import Data.Semigroup.Traversable+import Prelude hiding (lookup)++type Reader f = ReaderT f Identity++reader :: Representable f => (Key f -> b) -> Reader f b+reader = readerT . fmap Identity++runReader :: Indexable f => Reader f b -> Key f -> b+runReader = fmap runIdentity . runReaderT++-- * This 'tabulateresentable monad transformer' transforms any monad @m@ with a 'Representable' 'Monad'.+--   This monad in turn is also tabulateresentable if @m@ is 'Representable'.+newtype ReaderT f m b = ReaderT { getReaderT :: f (m b) }++readerT :: Representable f => (Key f -> m b) -> ReaderT f m b+readerT = ReaderT . tabulate++runReaderT :: Indexable f => ReaderT f m b -> Key f -> m b+runReaderT = index . getReaderT ++type instance Key (ReaderT f m) = (Key f, Key m)++instance (Functor f, Functor m) => Functor (ReaderT f m) where+  fmap f = ReaderT . fmap (fmap f) . getReaderT++instance (Representable f, Apply m) => Apply (ReaderT f m) where+  ReaderT ff <.> ReaderT fa = ReaderT ((<.>) <$> ff <.> fa)++instance (Representable f, Applicative m) => Applicative (ReaderT f m) where+  pure = ReaderT . pure . pure +  ReaderT ff <*> ReaderT fa = ReaderT ((<*>) <$> ff <*> fa)++instance (Representable f, Bind m) => Bind (ReaderT f m) where+  ReaderT fm >>- f = ReaderT $ tabulate (\a -> index fm a >>- flip index a . getReaderT . f)++instance (Representable f, Monad m) => Monad (ReaderT f m) where+  return = ReaderT . pure . return+  ReaderT fm >>= f = ReaderT $ tabulate (\a -> index fm a >>= flip index a . getReaderT . f)++instance (Representable f, Monad m, Key f ~ e) => MonadReader e (ReaderT f m) where +  ask = ReaderT (tabulate return)+  local f m = readerT $ \r -> runReaderT m (f r)+  +instance Representable f => MonadTrans (ReaderT f) where+  lift = ReaderT . pure ++instance (Representable f, Distributive m) => Distributive (ReaderT f m) where+  distribute = ReaderT . fmap distribute . collect getReaderT++instance (Keyed f, Keyed m) => Keyed (ReaderT f m) where+  mapWithKey f = ReaderT . mapWithKey (\k -> mapWithKey (f . (,) k)) . getReaderT++instance (Indexable f, Indexable m) => Indexable (ReaderT f m) where+  index = uncurry . fmap index . index . getReaderT++instance (Adjustable f, Adjustable m) => Adjustable (ReaderT f m) where+  adjust f (kf,km) = ReaderT . adjust (adjust f km) kf . getReaderT++instance (Lookup f, Lookup m) => Lookup (ReaderT f m) where+  lookup (k,k') (ReaderT fm) = lookup k fm >>= lookup k'++instance (Representable f, Representable m) => Representable (ReaderT f m) where+  tabulate = ReaderT . tabulate . fmap tabulate . curry+  +instance (Foldable f, Foldable m) => Foldable (ReaderT f m) where+  foldMap f = foldMap (foldMap f) . getReaderT++instance (Foldable1 f, Foldable1 m) => Foldable1 (ReaderT f m) where+  foldMap1 f = foldMap1 (foldMap1 f) . getReaderT++instance (FoldableWithKey f, FoldableWithKey m) => FoldableWithKey (ReaderT f m) where+  foldMapWithKey f = foldMapWithKey (\k -> foldMapWithKey (f . (,) k)) . getReaderT++instance (FoldableWithKey1 f, FoldableWithKey1 m) => FoldableWithKey1 (ReaderT f m) where+  foldMapWithKey1 f = foldMapWithKey1 (\k -> foldMapWithKey1 (f . (,) k)) . getReaderT ++instance (Traversable f, Traversable m) => Traversable (ReaderT f m) where+  traverse f = fmap ReaderT . traverse (traverse f) . getReaderT++instance (Traversable1 f, Traversable1 m) => Traversable1 (ReaderT f m) where+  traverse1 f = fmap ReaderT . traverse1 (traverse1 f) . getReaderT++instance (TraversableWithKey f, TraversableWithKey m) => TraversableWithKey (ReaderT f m) where+  traverseWithKey f = fmap ReaderT . traverseWithKey (\k -> traverseWithKey (f . (,) k)) . getReaderT++instance (TraversableWithKey1 f, TraversableWithKey1 m) => TraversableWithKey1 (ReaderT f m) where+  traverseWithKey1 f = fmap ReaderT . traverseWithKey1 (\k -> traverseWithKey1 (f . (,) k)) . getReaderT++instance (Representable f, Representable m, Semigroup (Key f), Semigroup (Key m)) => Extend (ReaderT f m) where+  extend = extendRep+  duplicate = duplicateRep++instance (Representable f, Representable m, Semigroup (Key f), Semigroup (Key m), Monoid (Key f), Monoid (Key m)) => Comonad (ReaderT f m) where+  extract = extractRep++instance (Representable f, MonadIO m) => MonadIO (ReaderT f m) where+  liftIO = lift . liftIO ++instance (Representable f, MonadWriter w m) => MonadWriter w (ReaderT f m) where+  tell = lift . tell+  listen (ReaderT m) = ReaderT $ tabulate $ Writer.listen . index m+  pass (ReaderT m) = ReaderT $ tabulate $ Writer.pass . index m+
+ Control/Monad/Representable/State.hs view
@@ -0,0 +1,221 @@+{-# LANGUAGE TypeFamilies+           , TypeSynonymInstances+           , FlexibleContexts+           , FlexibleInstances+           , MultiParamTypeClasses+           , UndecidableInstances #-}+----------------------------------------------------------------------+-- |+-- Module      :  Control.Monad.Representable.State+-- Copyright   :  (c) Edward Kmett & Sjoerd Visscher 2011+-- License     :  BSD3+-- +-- Maintainer  :  ekmett@gmail.com+-- Stability   :  experimental+-- +-- A generalized State monad, parameterized by a Representable functor.+-- The representation of that functor serves as the state.+----------------------------------------------------------------------+module Control.Monad.Representable.State+   ( State+   , state+   , runState+   , evalState+   , execState+   , mapState+   , StateT(..)+   , stateT+   , runStateT+   , evalStateT+   , execStateT+   , mapStateT+   , liftCallCC+   , liftCallCC'+   , get+   , gets+   , put+   , modify+   ) where++import Control.Applicative+import Data.Key+import Data.Functor.Bind+import Data.Functor.Bind.Trans+import Control.Monad.State.Class+import Control.Monad.Cont.Class+import Control.Monad.Reader.Class+import Control.Monad.Writer.Class+import Control.Monad.Free.Class+import Control.Monad.Trans.Class+import Control.Monad.Identity+import Data.Functor.Representable++-- ---------------------------------------------------------------------------+-- | 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++-- | Construct a state monad computation from a function.+-- (The inverse of 'runState'.)+state :: Representable g +      => (Key g -> (a, Key g))  -- ^ pure state transformer+      -> State g a              -- ^ equivalent state-passing computation+state f = stateT (Identity . f)++-- | Unwrap a state monad computation as a function.+-- (The inverse of 'state'.)+runState :: Indexable g +         => State g a   -- ^ state-passing computation to execute+         -> Key g       -- ^ initial state+         -> (a, Key g)  -- ^ return value and final state+runState m = runIdentity . runStateT m++-- | Evaluate a state computation with the given initial state+-- and return the final value, discarding the final state.+--+-- * @'evalState' m s = 'fst' ('runState' m s)@+evalState :: Indexable g +          => State g a  -- ^state-passing computation to execute+          -> Key g      -- ^initial value+          -> a          -- ^return value of the state computation+evalState m s = fst (runState m s)++-- | Evaluate a state computation with the given initial state+-- and return the final state, discarding the final value.+--+-- * @'execState' m s = 'snd' ('runState' m s)@+execState :: Indexable g+          => State g a  -- ^state-passing computation to execute+          -> Key g      -- ^initial value+          -> Key g      -- ^final state+execState m s = snd (runState m s)++-- | Map both the return value and final state of a computation using+-- the given function.+--+-- * @'runState' ('mapState' f m) = f . 'runState' m@+mapState :: Functor g => ((a, Key g) -> (b, Key g)) -> State g a -> State g b+mapState f = mapStateT (Identity . f . runIdentity)++-- ---------------------------------------------------------------------------+-- | A state transformer monad parameterized by:+--+--   * @g@ - A representable functor used to memoize results for a state @Key g@+--+--   * @m@ - The inner monad.+--+-- 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 { getStateT :: g (m (a, Key g)) } ++stateT :: Representable g => (Key g -> m (a, Key g)) -> StateT g m a+stateT = StateT . tabulate++runStateT :: Indexable g => StateT g m a -> Key g -> m (a, Key g)+runStateT (StateT m) = index m++mapStateT :: Functor g => (m (a, Key g) -> n (b, Key g)) -> StateT g m a -> StateT g n b+mapStateT f (StateT m) = StateT (fmap f m)++-- | Evaluate a state computation with the given initial state+-- and return the final value, discarding the final state.+--+-- * @'evalStateT' m s = 'liftM' 'fst' ('runStateT' m s)@+evalStateT :: (Indexable g, Monad m) => StateT g m a -> Key g -> m a+evalStateT m s = do+    (a, _) <- runStateT m s+    return a++-- | Evaluate a state computation with the given initial state+-- and return the final state, discarding the final value.+--+-- * @'execStateT' m s = 'liftM' 'snd' ('runStateT' m s)@+execStateT :: (Indexable g, Monad m) => StateT g m a -> Key g -> m (Key g)+execStateT m s = do+    (_, s') <- runStateT m s+    return s'++instance (Functor g, Functor m) => Functor (StateT g m) where+  fmap f = StateT . fmap (fmap (\ ~(a, s) -> (f a, s))) . getStateT++instance (Functor g, Indexable g, Bind m) => Apply (StateT g m) where+  mf <.> ma = mf >>- \f -> fmap f ma++instance (Representable g, Functor m, Monad m) => Applicative (StateT g m) where+  pure = StateT . leftAdjunctRep return+  mf <*> ma = mf >>= \f -> fmap f ma++instance (Functor g, Indexable g, Bind m) => Bind (StateT g m) where+  StateT m >>- f = StateT $ fmap (>>- rightAdjunctRep (runStateT . f)) m+   +instance (Representable g, Monad m) => Monad (StateT g m) where+  return = StateT . leftAdjunctRep return+  StateT m >>= f = StateT $ fmap (>>= rightAdjunctRep (runStateT . f)) m++instance Representable f => BindTrans (StateT f) where+  liftB m = stateT $ \s -> fmap (\a -> (a, s)) m++instance Representable f => MonadTrans (StateT f) where+  lift m = stateT $ \s -> liftM (\a -> (a, s)) m++instance (Representable g, Monad m, Key g ~ s) => MonadState s (StateT g m) where+  get = stateT $ \s -> return (s, s)+  put s = StateT $ pure $ return ((),s)++-- get :: (Representable g, Monad m) => StateT g m (Key g)+-- put :: (Applicative g, Monad m) => Key g -> StateT g m ()++-- gets :: (Representable g, Monad m) => (Key g -> s) -> StateT g m s+-- gets f = liftM f get++-- modify :: (Representable g, Monad m) => (Key g -> Key g) -> StateT g m ()+-- modify f = stateT $ \s -> return ((), f s)++instance (Representable g, MonadReader e m) => MonadReader e (StateT g m) where+  ask = lift ask+  local = mapStateT . local++instance (Representable g, MonadWriter w m) => MonadWriter w (StateT g m) where+  tell = lift . tell+  listen = mapStateT $ \ma -> do+     ((a,s'), w) <- listen ma+     return ((a,w), s')+  pass = mapStateT $ \ma -> pass $ do+    ((a, f), s') <- ma+    return ((a, s'), f)++instance (Representable g, MonadCont m) => MonadCont (StateT g m) where+    callCC = liftCallCC' callCC++instance (Functor f, Representable g, MonadFree f m) => MonadFree f (StateT g m) where+    wrap as = stateT $ \s -> wrap (fmap (`runStateT` s) as)+  +leftAdjunctRep :: Representable u => ((a, Key u) -> b) -> a -> u b+leftAdjunctRep f a = tabulate (\s -> f (a,s))++rightAdjunctRep :: Indexable u => (a -> u b) -> (a, Key u) -> b+rightAdjunctRep f ~(a, k) = f a `index` k++-- | 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+liftCallCC callCC' f = stateT $ \s ->+    callCC' $ \c ->+    runStateT (f (\a -> StateT $ pure $ c (a, s))) s++-- | 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+liftCallCC' callCC' f = stateT $ \s ->+    callCC' $ \c ->+    runStateT (f (\a -> stateT $ \s' -> c (a, s'))) s+
representable-functors.cabal view
@@ -1,6 +1,6 @@ name:          representable-functors category:      Monads, Functors, Data Structures-version:       0.5.0+version:       1.8.0 license:       BSD3 cabal-version: >= 1.6 license-file:  LICENSE@@ -22,19 +22,24 @@     array >= 0.3.0.2 && < 0.4,     base >= 4 && < 4.4,     comonad >= 1.1 && < 1.2,-    comonad-transformers >= 1.7 && < 1.8,     containers >= 0.3 && < 0.5,     contravariant >= 0.1.2 && < 0.2,     distributive >= 0.2 && < 0.3,-    keys >= 0.3 && < 0.4,     mtl >= 2.0.1.0 && < 2.1,     semigroups >= 0.5 && < 0.6,     semigroupoids >= 1.2.2 && < 1.3.0,-    transformers >= 0.2.0 && < 0.3+    transformers >= 0.2.0 && < 0.3,+    keys                 >= 1.8 && < 1.9,+    free                 >= 1.8 && < 1.9,+    comonad-transformers >= 1.8 && < 1.9,+    comonads-fd          >= 1.8 && < 1.9,+    data-lens            >= 1.8 && < 1.9    exposed-modules:     Data.Functor.Corepresentable     Data.Functor.Representable-    Control.Monad.Representable+    Control.Monad.Representable.Reader+    Control.Monad.Representable.State+    Control.Comonad.Representable.Store    ghc-options: -Wall