
Hi Daniel,
What I need to see is a function, say g, that lifts the function f (in the List monad) into the StateT monad, applies it to the monad's value, say 1, and returns a result [0,1].
Or, alternatively, code that lifts a function in the State monad, say tick
import Control.Monad.State
type GeneratorState = State Int
tick :: GeneratorState Int
tick = do n <- get
put (n+1)
return n
into the ListT monad and applies it to a list, say
lst = [0,1,2]
producing [(0,1),(1,2),(2,3)].
Both would be very helpful. Or maybe I'm missing the concept of monad transformers altogether and putting them together improperly, like trying to use a spreadsheet to write a letter?
Michael
--- On Thu, 1/13/11, Daniel Fischer
{- 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.
lift (f n) = StateT (\s -> [(k,s) | k <- [0 .. n]]) Generally, lift list = StateT (\s -> zip list (repeat s))
Michael