Haskell“不是构造函数的可见字段”错误
我收到一个我不太明白的错误:
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
import qualified SomeModule as M
import qualified AnotherModule as A
main = print $ A.makeSomeType M.Constructor1
SomeModule.hs
module SomeModule (SomeType(..), AnotherType(..)) where
data SomeType = SomeType { something :: [String]
, somethingElse :: [AnotherType]
} deriving (Show)
data AnotherType = Constructor1
| Constructor2
deriving (Show)
AnotherModule.hs
module AnotherModule (makeSomeType) where
import qualified SomeModule as M
makeSomeType :: M.AnotherType -> M.SomeType
makeSomeType something = M.SomeType { something = []
, somethingElse = [something]
}
I'm getting an error I don't quite understand:
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'
Can anyone explain why I'm getting this error and how I might go about fixing it?
Main.hs
import qualified SomeModule as M
import qualified AnotherModule as A
main = print $ A.makeSomeType M.Constructor1
SomeModule.hs
module SomeModule (SomeType(..), AnotherType(..)) where
data SomeType = SomeType { something :: [String]
, somethingElse :: [AnotherType]
} deriving (Show)
data AnotherType = Constructor1
| Constructor2
deriving (Show)
AnotherModule.hs
module AnotherModule (makeSomeType) where
import qualified SomeModule as M
makeSomeType :: M.AnotherType -> M.SomeType
makeSomeType something = M.SomeType { something = []
, somethingElse = [something]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
something
和somethingElse
基本上是在SomeModule
中定义的函数。尝试something
andsomethingElse
are basically functions defined inSomeModule
. Try