Difference between revisions of "Talk:Monad/ST"
Jump to navigation
Jump to search
m (An unevaluated thunk will build up in the STRef in the last example) |
(No difference)
|
Revision as of 23:12, 24 August 2011
I think there is another caveat in that last example which is supposed to run in constant space.
The lines (in the last code example)
x' <- readSTRef x y' <- readSTRef y writeSTRef x y' writeSTRef y (x'+y')
will build up a long unevaluated sum (1+1+2+3+5+8+..) in the STRef, which takes up stack space. When compiled I get a stack overflow around for fibST 1100000 (1.1 million) with a stack size of 8MB. There might be some hidden strictness in that "The ST monad provides support for strict state threads." but that isn't explained in this page.