3 ms·
ST is the efficient version of the State Monad. Where did you come to think that St was short for single threaded?
by vamega 11y ago
ST is the efficient version of the State Monad. Where did you come to think that St was short for single threaded?
- chriswarbo 11y agoFrom https://wiki.haskell.org/Monad/ST https://wiki.haskell.org/Monad/ST > The ST monad lets you use update-in-place, but is escapable (unlike IO). ST actions have the form: ST s α > Meaning that they return a value of type α, and execute in "thread" s. All reference types are tagged with the thread, so that actions can only affect references in their own "thread". > Now, the type of the function used to escape ST is: runST :: forall α. (forall s. ST s α) -> α > The action you pass must be universal in s, so inside your action you don't know what thread, thus you cannot access any other threads, thus runST is pure. This is very useful, since it allows you to implement externally pure things like in-place quicksort, and present them as pure functions ∀ e. Ord e ⇒ Array e → Array e; without using any unsafe functions.