-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Python-generators notation for creation of monadic lists -- -- Consumer and Generator monad transformers to create and iterate -- ListTs in a manner similar to Python generators. @package generator @version 0.5.2 -- | A monad transformer for the [partial] consumption of Lists. The -- interface closely mimics iterators in languages such as Python. -- -- It is often nicer to avoid using Consumer and to use folds and -- higher-order functions instead. module Control.Monad.Consumer -- | A monad tranformer for consuming Lists. data ConsumerT v m a -- | Consume a ListT evalConsumerT :: (List l) => ConsumerT v (ItemM l) a -> l v -> ItemM l a -- | Consume/get the next value next :: (Monad m) => ConsumerT v m (Maybe v) -- | Return an instance of the underlying monad that will use the given -- ConsumerT to consume the remaining values. After this action -- there are no more items to consume (they belong to the given ConsumerT -- now) consumeRestM :: (Monad m) => ConsumerT a m b -> ConsumerT a m (m b) instance (MonadIO m) => MonadIO (ConsumerT v m) instance MonadTrans (ConsumerT v) instance (Monad m) => Applicative (ConsumerT v m) instance (Monad m) => Monad (ConsumerT v m) instance (Monad m) => Functor (ConsumerT v m) -- | A difference-list monad transformer / a monadic difference-list. -- -- Difference lists are lists with O(1) append (instead of -- O(N)). -- -- Transforming a difference list to a list is O(1), a must be -- done to access a difference list. The transformation from a list to a -- difference list is O(N). module Control.Monad.DList -- | A monadic difference-list newtype DListT m a DListT :: (ListT m a -> ListT m a) -> DListT m a runDListT :: DListT m a -> ListT m a -> ListT m a instance MonadTrans DListT instance (Monad m) => List (DListT m) instance (Monad m) => MonadPlus (DListT m) instance (Monad m) => Applicative (DListT m) instance (Monad m) => Monad (DListT m) instance (Monad m) => Functor (DListT m) instance Monoid (DListT l a) -- | A monad transformer for the creation of Lists. Similar to Python's -- generators. -- --
-- import Data.List.Class (convList)
--
-- hanoi 0 _ _ _ = mempty
-- hanoi n from to other =
-- generate $ do
-- yields $ hanoi (n-1) from other to
-- yield (from, to)
-- yields $ hanoi (n-1) other to from
--
-- > convList (hanoi 3 'A' 'B' 'C') :: [(Char, Char)]
-- [('A','B'),('A','C'),('B','C'),('A','B'),('C','A'),('C','B'),('A','B')]
--
module Control.Monad.Generator
-- | A monad transformer to create Lists. generate transforms a
-- GeneratorT v m a to a DListT m a.
data GeneratorT v m a
-- | O(1), Transform a GeneratorT to a DListT
generate :: (Monad m) => GeneratorT v m () -> DListT m v
-- | O(1), Output a result value
yield :: (Monad m) => v -> GeneratorT v m ()
-- | O(1), Output all the values of a DListT.
yields :: (Monad m) => DListT m v -> GeneratorT v m ()
instance (MonadIO m) => MonadIO (GeneratorT v m)
instance MonadTrans (GeneratorT v)
instance (Monad m) => Applicative (GeneratorT v m)
instance (Monad m) => Monad (GeneratorT v m)
instance (Monad m) => Functor (GeneratorT v m)