我有這個核心 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
它需要使用下面的 Relation 建構式:
{-# 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 中洗掉“import Relation ...”中的詳細資訊,并且它作業正常。
但我想保留詳細的匯入。
洗掉此匯入后,在 GHCi 解釋器中,我可以看到 Relation 建構式型別:
*Main> import Relation
*Main Relation> :t Relation
Relation
:: Schema schemaField
-> Rows valueField -> Relation schemaField valueField
那么,我在詳細匯入中遺漏了什么?
我檢查了這 2 個 StackOverflow 執行緒,但沒有找到任何解決方案:
- Haskell:不在范圍內:資料建構式
- Not in scope: data constructor?
uj5u.com熱心網友回復:
在RelationTest.hs檔案中,您Relation使用以下命令從模塊中匯入特定的型別建構式:
import Relation (FromValueToSchema,bindType,schema,rows,Relation)
當涉及到資料型別時,這只匯入型別建構式。不會匯入資料建構式、可能的方法和欄位名稱。在(..)型別建構式或類的末尾添加 a將匯入它們所有可能的成員。像下面這樣:
import Relation (FromValueToSchema,bindType,schema,rows,Relation(..))
Haskell 報告的第 5.3.1 節指出:
可以通過以下三種方式之一指定要匯入的確切物體:
- 可以通過在括號中列出它們來明確指定匯入的物體。串列中的專案與匯出串列中的專案具有相同的形式,除了不允許使用限定符并且不允許使用 `module modid' 物體。當匯入的 (..) 形式用于型別或類時,(..) 指的是從模塊匯出的所有建構式、方法或欄位名稱。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/350112.html
下一篇:遍歷一個字串并使用每個字符,但我收到此例外訊息:“(48,1)-(50,35):函式textToMorse中的非窮舉模式”
