[Haskell-beginners] Using StateT with List monad
Nathan Hüsken
nathan.huesken at posteo.de
Sat Nov 24 14:52:42 CET 2012
Hey,
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.
twoSucc :: StateT Int [] ()
twoSucc = do
i <- get
put (i+1) -- how do I put [i+1,i+2] here?
As mentioned in the comment, when doing
runStateT twoSucc n
it outputs [((),n+1)] (which makes sense). How do I write it that it
behaves similar to the original twoSucc and outputs [((),n+1),((),n+2)]?
Thanks!
Nathan
More information about the Beginners
mailing list