Does ST monad have special compiler support in GHC?
You can see the code for STRefs here: http://haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-STRef.html
It uses, clearly, MutVar#
primitives. The runST
code similarly uses the RealWorld#
primitive and unboxed tuples. However, given simply IORefs and unsafePerformIO
you could build your own ST
monad with the same big-O properties, although probably less overall efficiency.
Section 9 of State in Haskell might be of interest. I didn't read closely enough to tell whether what they described there actually requires compiler support, but it did sound like implementing some of the primitives in the compiler was the path of least resistance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With