[Haskell-beginners] Using StateT with List monad
Karl Voelker
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
really want.
-Karl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121124/6aa8afa5/attachment.htm>
More information about the Beginners
mailing list