[Haskell-beginners] Using StateT with List monad
ktvoelker at gmail.com
Sat Nov 24 19:12:03 CET 2012
On Sat, Nov 24, 2012 at 5:52 AM, Nathan Hüsken <nathan.huesken at posteo.de>wrote:
> I have an example function in the list monad.
> twoSucc :: Int -> [Int]
> twoSucc i = [i+1, i+2]
> Now I want write something similar with the StateT monad transformer.
The simplest addition of StateT would look like this:
twoSucc :: StateT ()  Int
twoSucc i = lift [i+1, i+2]
> twoSucc :: StateT Int  ()
> twoSucc = do
> i <- get
> put (i+1) -- how do I put [i+1,i+2] here?
In this transformation, you've moved your Int result from being the monadic
result to being the stored state. I don't know which transformation you
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners