[Haskell-cafe] Monad transformer: apply StateT to List monad

michael rice nowgate at yahoo.com
Thu Jan 13 21:17:41 CET 2011


{- From: http://en.wikibooks.org/wiki/Haskell/Monad_transformers
if for instance we apply StateT to the List monad, a function that returns a list (i.e., a computation in the List monad) can be lifted into StateT s [], where it becomes a function that returns a StateT (s -> [(a,s)]). That is, the lifted computation produces multiple (value,state) pairs from its input state.
-}

import Control.Monad.Trans.State.Lazy

type GeneratorState = StateT Int

-- a function in the list monad
f :: Int -> [Int]
f n = [0..n]

Will someone please demonstrate the above comment from the wiki page.

Michael




      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110113/33d4f4c5/attachment.htm>


More information about the Haskell-Cafe mailing list