by jorkadeen · 1y ago · 0 comments
(I am one of the developers of Flix)
It's usage is almost equivalent to using IORefs, except we can escape ST using runST to get back a pure value not in ST, which we cannot do for IO because there is no `IO a -> a`.
There's no requirement to contain ST to a single function - we can split mutation over several functions, provided each one involved returns some `ST a` and their usage is combined with >>=.
Note that there is no requirement that all mutation must occur within a single function. The requirement is that once you leave the lexical scope then all mutable memory associated with that scope become unreachable. Mutation can certainly span over multiple functions.
unsafePerformIO :: IO a -> a
Do you mean "cannot do with safety guarantee"? Strangely enough, the haskell docs use the same language as you: The ST monad allows for destructive updates, but is escapable (unlike IO).
___0. https://hackage.haskell.org/package/base-4.21.0.0/docs/Syste...