Haskell “哈斯克尔”;不是构造函数的可见字段“;错误
我犯了一个我不太明白的错误:Haskell “哈斯克尔”;不是构造函数的可见字段“;错误,haskell,constructor,algebraic-data-types,Haskell,Constructor,Algebraic Data Types,我犯了一个我不太明白的错误: AnotherModule.hs:6:38: `something' is not a (visible) field of constructor `M.SomeType' AnotherModule.hs:7:38: `somethingElse' is not a (visible) field of constructor `M.SomeType' 有人能解释一下我为什么会出现这个错误,以及我该如何着手修复它吗 Main.hs SomeM
AnotherModule.hs:6:38:
`something' is not a (visible) field of constructor `M.SomeType'
AnotherModule.hs:7:38:
`somethingElse' is not a (visible) field of constructor `M.SomeType'
有人能解释一下我为什么会出现这个错误,以及我该如何着手修复它吗
Main.hs
SomeModule.hs
AnotherModule.hs
something
和somethingElse
基本上是SomeModule
中定义的函数。试一试
makeSomeType something = M.SomeType { M.something = []
, M.somethingElse = [something]
}
module SomeModule (SomeType(..), AnotherType(..)) where
data SomeType = SomeType { something :: [String]
, somethingElse :: [AnotherType]
} deriving (Show)
data AnotherType = Constructor1
| Constructor2
deriving (Show)
module AnotherModule (makeSomeType) where
import qualified SomeModule as M
makeSomeType :: M.AnotherType -> M.SomeType
makeSomeType something = M.SomeType { something = []
, somethingElse = [something]
}
makeSomeType something = M.SomeType { M.something = []
, M.somethingElse = [something]
}