Why does this simple use of the State monad cause a stack overflow?
问题 I was playing around with the State monad, and I don't know what's causing the stack overflow in this simple piece of code. import Control.Monad.State.Lazy tick :: State Int Int tick = do n <- get put $! (n+1) return n million :: Int million = snd $ runState (mapM_ (const tick) [1..1000000]) 0 main = print million Note I would just like to know what's causing the problem in this piece of code, the task itself is not important per se. 回答1: The problem is that Control.Monad.State.Lazy's (>>=)