ST monad 有特殊的编译器支持吗?
ST monad 在 GHC 中有特殊的编译器支持吗?
Does ST monad have special compiler support in GHC?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
ST monad 在 GHC 中有特殊的编译器支持吗?
Does ST monad have special compiler support in GHC?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
您可以在此处查看 STRef 的代码: http://haskell.org /ghc/docs/latest/html/libraries/base/src/GHC-STRef.html
显然,它使用
MutVar#
原语。runST
代码类似地使用RealWorld#
原语和未装箱的元组。然而,只要给出 IORefs 和 unsafePerformIO,您就可以构建自己的具有相同 big-O 属性的 ST monad,尽管总体效率可能较低。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. TherunST
code similarly uses theRealWorld#
primitive and unboxed tuples. However, given simply IORefs andunsafePerformIO
you could build your ownST
monad with the same big-O properties, although probably less overall efficiency.Haskell 中的第 9 节 可能会感兴趣。我没有仔细阅读,无法判断他们所描述的内容是否实际上需要编译器支持,但听起来确实是在编译器中实现某些原语是阻力最小的路径。
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.