GHC版本检入代码 [英] GHC version check in code

查看:129
本文介绍了GHC版本检入代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对亚历克斯作出了贡献,它显然取决于很多库,应该编译为很多版本。

I'm contributing to Alex, and it obviously depends on a lot of libraries and should compile for a lot of versions.

我需要使用一个只能从 GHC 7.6.1 使用的函数来更好地处理错误。所以我想用 #if ... 来导入这个函数,否则,我会以不同的方式处理这个错误。

I need to use a function that is only available from GHC 7.6.1 to handle an error better. So I want to use an #if ... to import said function, else, I'll deal with the error differently.

我见过一些:

I've seen some:

#if __GLASGOW_HASKELL__ >= 610
import Control.Exception ( bracketOnError )
#endif

所以我做了:

So I did:

#if __GLASGOW_HASKELL__ >= 761
import Text.Read ( readMaybe )
#endif

认为 761 是GHC版本 7.6.1的别名,当我构建cabal包并试用时,即使使用 Glorious Glasgow Haskell编译系统, 7.8.4版<

Thinking that 761 is an alias to GHC version 7.6.1, when I build the cabal package and try it out, the function doesn't get imported, even though I use The Glorious Glasgow Haskell Compilation System, version 7.8.4.

所以在使用程序试用后,我发现 7.8.1 __ GLASGOW_HASKELL __ 中标识为 708

So after using a program to try it out, I find out that 7.8.1 identifies in __GLASGOW_HASKELL__ as 708.

{-# LANGUAGE CPP #-}
module Main where

#if __GLASGOW_HASKELL__ == 708
ver = "==708"
#else
ver = "/=708"
#endif

main = putStrLn $ ver

并运行它:

And running it:

$ runhaskell if.hs
==708

我怎样才能知道什么值应该用于 7.6.1 ,还是有更好的方法来处理这个问题?

How can I know what value should I use for 7.6.1, or is there a better way to deal with this?

推荐答案

这在 GHC用户指南第6.11.3.1节:

That's described in section 6.11.3.1 of GHC's users guide:


对于版本 xyz 的GHC, __ GLASGOW_HASKELL __ 的值是整数⟨xyy⟩(如果⟨y⟩是单个数字,则添加前导零,所以例如在GHC的6.2版中, __ GLASGOW_HASKELL __ == 602 )。更多信息请参阅 GHC版本编号政策

For version x.y.z of GHC, the value of __GLASGOW_HASKELL__ is the integer ⟨xyy⟩ (if ⟨y⟩ is a single digit, then a leading zero is added, so for example in version 6.2 of GHC, __GLASGOW_HASKELL__==602). More information in GHC version numbering policy.

因此,对于 7.6.1 ,您可以选中 __ GLASGOW_HASKELL__> = 706 。原因是 7.10.x

So for 7.6.1, you would check __GLASGOW_HASKELL__ >= 706. The reason for this are versions like 7.10.x.

这篇关于GHC版本检入代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆