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) |
|||
Line 6: | Line 6: | ||
writeSTRef x y' |
writeSTRef x y' |
||
writeSTRef y (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 |
+ | 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 when running ''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. |
Revision as of 23:15, 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 when running 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.