generator-0.5.3: Python-generators notation for creation of monadic listsSource codeContentsIndex
Control.Monad.Generator
Description

A monad transformer for the creation of Lists. Similar to Python's generators.

 import Control.Monad.DList (toListT)
 import Control.Monad.Identity (Identity(..))
 import Data.List.Class (toList)

 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

 > runIdentity . toList . toListT $ hanoi 3 'A' 'B' 'C' :: [(Char, Char)]
 [('A','B'),('A','C'),('B','C'),('A','B'),('C','A'),('C','B'),('A','B')]
Synopsis
data GeneratorT v m a
generate :: Monad m => GeneratorT v m () -> DListT m v
yield :: Monad m => v -> GeneratorT v m ()
yields :: Monad m => DListT m v -> GeneratorT v m ()
Documentation
data GeneratorT v m a Source
A monad transformer to create Lists. generate transforms a GeneratorT v m a to a DListT m a.
show/hide Instances
generate :: Monad m => GeneratorT v m () -> DListT m vSource
O(1), Transform a GeneratorT to a DListT
yield :: Monad m => v -> GeneratorT v m ()Source
O(1), Output a result value
yields :: Monad m => DListT m v -> GeneratorT v m ()Source
O(1), Output all the values of a DListT.
Produced by Haddock version 2.6.0