13 ms·
> not all assignment makes a function impure That's exactly what the ST monad/STRef's are for. {new,read,write}STRef let you manipulate mutable references whil
by aweinstock 9y ago
> not all assignment makes a function impure
That's exactly what the ST monad/STRef's are for. {new,read,write}STRef let you manipulate mutable references while keeping track of their scope in the type of the reference. runST encapsulates a chunk of code that manipulates mutable variables in an externally-pure way into a pure function. The "Lazy Functional State Threads"[1] paper on it is a pretty good read.
[1]: https://www.microsoft.com/en-us/research/wp-content/uploads/1994/06/lazy-functional-state-threads.pdf https://www.microsoft.com/en-us/research/wp-content/uploads/...