我有一个核心Haskell文件: Relation.hs
定义了一些数据类型。
{-# LANGUAGE GADTs,MultiParamTypeClasses,ScopedTypeVariables,TypeSynonymInstances,FlexibleInstances #-}
module Relation where
data SchemaField schemaField where
SchemaField :: (Eq fieldType) => {
name :: String,
fieldType :: fieldType,
nullable :: Bool
} -> SchemaField (String,fieldType,Bool)
data ValueField valueField where
ValueField :: (Eq valueField,Ord valueField) => valueField -> ValueField valueField
type Schema schemaField = [SchemaField schemaField]
type MaybeValueField valueField = Maybe (ValueField valueField)
type Row valueField = [MaybeValueField valueField]
type Rows valueField = [Row valueField]
data Relation schemaField valueField = Relation {
schema :: Schema schemaField,
rows :: Rows valueField
}然后,我得到了测试文件: RelationTest.hs
它需要使用下面的关系构造函数:
{-# LANGUAGE MultiParamTypeClasses #-}
module RelationTest where
import Relation (FromValueToSchema,bindType,schema,rows,Relation)
data FieldType =
StringType | IntType -- Char | Bool | Integer | Float | Double
deriving (Show,Eq)
consistentSchema = [SchemaField "name" StringType False,SchemaField "ID" IntType True]
createdRelation = Relation {schema = consistentSchema, rows = []}但是当我编译RelationTest.hs时,我不理解这个错误:不在作用域:数据构造函数的关系‘
从理解上看,关系构造函数是在Relation.hs中定义的。
我可以删除“导入关系”中的细节.在RelationTest.hs中,它工作得很好。
但是我想保持详细的进口。
当删除此导入时,在GHCi解释器中,我可以看到关系构造函数类型:
*Main> import Relation
*Main Relation> :t Relation
Relation
:: Schema schemaField
-> Rows valueField -> Relation schemaField valueField那么,我在我的详细进口中错过了什么呢?
我检查了这两个StackOverflow线程,但没有找到任何解决方案:
发布于 2021-11-04 19:39:40
在RelationTest.hs文件中,您将使用以下方法从Relation模块导入特定类型的构造函数:
import Relation (FromValueToSchema,bindType,schema,rows,Relation)当涉及数据类型时,这只导入类型构造函数。不导入数据构造函数、可能的方法和字段名。将(..)添加到类型构造函数或类的末尾将导入其所有可能的成员。如下:
import Relation (FromValueToSchema,bindType,schema,rows,Relation(..))Haskell报告第5.3.1节规定:
可以通过以下三种方式之一指定要导入的实体:
https://stackoverflow.com/questions/69844212
复制相似问题