ST monad 有特殊的编译器支持吗?

发布于 2024-12-15 22:20:26 字数 34 浏览 5 评论 0原文

ST monad 在 GHC 中有特殊的编译器支持吗?

Does ST monad have special compiler support in GHC?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泛泛之交 2024-12-22 22:20:26

您可以在此处查看 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. 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.

李不 2024-12-22 22:20:26

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文