generator-0.5.4: Python-generators notation for creation of monadic lists

Control.Monad.Generator

Description

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

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

 hanoi 0 _ _ _ = return ()
 hanoi n from to other = do
   hanoi (n-1) from other to
   yield (from, to)
   hanoi (n-1) other to from

 > runIdentity . toList . generate $ hanoi 3 'A' 'B' 'C' :: [(Char, Char)]
 [('A','B'),('A','C'),('B','C'),('A','B'),('C','A'),('C','B'),('A','B')]

Synopsis

Documentation

newtype GeneratorT v m a Source

A monad transformer to create Lists. generate transforms a GeneratorT v m a to a ListT m a.

Constructors

GeneratorT 

Fields

runGeneratorT :: ContT v (ListT m) a
 

Instances

yield :: Monad m => v -> GeneratorT v m ()Source