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

Safe HaskellSafe-Inferred
LanguageHaskell98

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

generate :: Monad m => GeneratorT v m () -> ListT m v Source

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