如何在没有长长的 CPP if/else 条件列表的情况下在代码中获取 haskell 编译器版本?
按照以下路线的内容:
import GHC.Version qualified
main :: IO ()
main = print $ GHC.Version.current
-- would print Version 8 10 7
回旋方式是从Shell中执行GHC - Version
:
import System.Process
main = system "ghc --version"
但是,当运行GHC与GHC
不相同时,这可能是不正确的。在路径
中。
Something along the lines of:
import GHC.Version qualified
main :: IO ()
main = print $ GHC.Version.current
-- would print Version 8 10 7
A roundabout way is to execute ghc --version
from shell:
import System.Process
main = system "ghc --version"
but this may be incorrect when the running GHC isn't the same as the ghc
in PATH
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,有两种方式。第一个使用
System.Info.compilerVersion< /code>
第二个通过
CPP
语言扩展:文档说明该数字如何已经想出来了。
Yes, in two ways. The first using
System.Info.compilerVersion
Second via the
CPP
language extension:Docs on how that number has been come up with.