Haskell 错误不在范围内 : data constructor

标签 haskell

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

相关文章:

haskell - ghc 8.0 cabal 构建错误 "ld: -r and -pie may not be used together"已知吗?

Haskell:我应该使用 Data.Text.Lazy.Builder 来构造我的 Text 值吗?

performance - `friday` 包很慢

haskell - 使用 Newtype 包

haskell - 在Scheme中柯里化(Currying) map

haskell - 在 Happy 和 Alex 中推回 token

haskell - 单独使用的括号 () 是什么意思?

haskell - Control.MonadPlus.Free 没有不必要的分发

haskell - 在类型级别未定义

haskell - 为什么 cabal 不能保留同一个包的多个版本?