问题描述
我有一个代码使用定义在GHC 8.2中的 fromRight
函数。但我需要降级到GHC 8.0.2,它给出变量不在范围内的错误:
对于 fromRight
我想知道是否有可能以及如何添加缺少的定义
fromRight :: b - >无论是b - > b
来自Right _(右b)= b
来自Right b _ = b
所以只有当我使用GHC版本比8.2.1时才使用它?
> import Prelude hiding(fromRight)
即使Prelude中不存在 fromRight
也是有效的。因此,如果你想编写一个兼容旧版和新版Prelude的模块,你可以简单地选择忽略来自Right 的新的函数,并且总是使用在你的图书馆。
I have a code that uses the fromRight
function defined circa GHC 8.2. But I need to downgrade to GHC 8.0.2, which gives an error about Variable not in scope:
for fromRight
I was wondering if it possible and how to add the missing definition
fromRight :: b -> Either a b -> b
fromRight _ (Right b) = b
fromRight b _ = b
so that it is only used when I use an GHC version than 8.2.1?
You can always write
import Prelude hiding (fromRight)
which is valid even if fromRight
does not exist in Prelude. Therefore, if you want to write a module which is compatible with both old and new versions of Prelude, you can simply choose to ignore the new fromRight
function, and always use the one in your library.
这篇关于如何为GHC中的旧版本定义函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!