为什么 运行 GHCi in Windows 无法检测到无限循环?
Why does running GHCi in Windows make it not possible to detect infinite loops?
我目前正在阅读 "Haskell Programming from first principles",关于 bottom 的部分中有一段内容为:
Let us examine a few ways by which we can have bottom in our programs:
Prelude> let x = x in x
*** Exception: << loop >>
Here GHCi detected that let x = x in x was never going to return and short-circuited the never-ending
computation. This is an exam- ple of bottom because it was never going
to return a result. Note that if you’re using a Windows computer, this
example may freeze your GHCi and not throw an exception.
我的问题是:Windows 是否有任何内在因素导致无法或难以检测到此循环,或者它是否仅特定于 GHC(i) 实现?
该评论似乎已过时。我可以确认在 Linux 上的 GHCi 8.6.4 中,在交互式提示中输入此代码只是挂起。
另外,如果你参加这个项目:
main = let x = x in x
并用 GHC 8.6.4 编译它(再次在 Linux 上),然后在没有优化的情况下编译它挂起,而用 -O2
编译它打印:
Loop: <<loop>>
是否编译线程似乎没有什么区别
最重要的是,GHC 无法真正保证它可能会或可能不会出现哪些无限循环 "catch",并且这会随着版本和不同的优化设置而变化,并且在交互与非交互中代码,并且可能因架构而异。
Windows 没有任何内在的东西可以阻止此检测过程,也没有特别的理由说明为什么 Windows 和 Linux 版本的程序会表现不同。如果注释在某一点上是准确的,则可能是 Windows 下代码生成的一些细微差异导致了观察到的行为差异。
我目前正在阅读 "Haskell Programming from first principles",关于 bottom 的部分中有一段内容为:
Let us examine a few ways by which we can have bottom in our programs:
Prelude> let x = x in x
*** Exception: << loop >>
Here GHCi detected that let x = x in x was never going to return and short-circuited the never-ending computation. This is an exam- ple of bottom because it was never going to return a result. Note that if you’re using a Windows computer, this example may freeze your GHCi and not throw an exception.
我的问题是:Windows 是否有任何内在因素导致无法或难以检测到此循环,或者它是否仅特定于 GHC(i) 实现?
该评论似乎已过时。我可以确认在 Linux 上的 GHCi 8.6.4 中,在交互式提示中输入此代码只是挂起。
另外,如果你参加这个项目:
main = let x = x in x
并用 GHC 8.6.4 编译它(再次在 Linux 上),然后在没有优化的情况下编译它挂起,而用 -O2
编译它打印:
Loop: <<loop>>
是否编译线程似乎没有什么区别
最重要的是,GHC 无法真正保证它可能会或可能不会出现哪些无限循环 "catch",并且这会随着版本和不同的优化设置而变化,并且在交互与非交互中代码,并且可能因架构而异。
Windows 没有任何内在的东西可以阻止此检测过程,也没有特别的理由说明为什么 Windows 和 Linux 版本的程序会表现不同。如果注释在某一点上是准确的,则可能是 Windows 下代码生成的一些细微差异导致了观察到的行为差异。