gpt4 book ai didi

Haskell 错误不在范围内 : data constructor

转载 作者:行者123 更新时间:2023-12-01 22:55:54 24 4
gpt4 key购买 nike

我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com