我在 Haskell 中编写了一些简单的模块,然后 import
它在其他文件中。然后我尝试将函数与我的模块中的数据构造函数一起使用 - 出现错误 Not in scope: data constructor: <value>
。我该如何修复它?
注意:当我导入后在解释器中使用它时 - 一切都很好,没有错误。
我的模块Test.hs
:
module Test (test_f) where
data Test_Data = T|U|F deriving (Show, Eq)
test_f x
| x == T = T
| otherwise = F
还有我的文件 file.hs
:
import Test
some_func = test_f
如果我用解释器编写,则不会出现错误:
> :l Test
> test_f T
T
在解释器中我试图执行 some_func T
,但是有一个错误。我该如何使用类 Test_Data
在我的文件中描述注释?
最佳答案
您没有从模块中导出它:
module Test (test_f, Test_Data(..)) where
(..)
部分表示“导出 TestData
的所有构造函数”。
关于Haskell 错误不在范围内 : data constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22200939/