ick*_*fay 13 constructor haskell 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'
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释为什么我会收到这个错误以及如何修复它?
import qualified SomeModule as M
import qualified AnotherModule as A
main = print $ A.makeSomeType M.Constructor1
Run Code Online (Sandbox Code Playgroud)
module SomeModule (SomeType(..), AnotherType(..)) where
data SomeType = SomeType { something :: [String]
, somethingElse :: [AnotherType]
} deriving (Show)
data AnotherType = Constructor1
| Constructor2
deriving (Show)
Run Code Online (Sandbox Code Playgroud)
module AnotherModule (makeSomeType) where
import qualified SomeModule as M
makeSomeType :: M.AnotherType -> M.SomeType
makeSomeType something = M.SomeType { something = []
, somethingElse = [something]
}
Run Code Online (Sandbox Code Playgroud)
gre*_*rep 16
something并且somethingElse基本上是在中定义的函数SomeModule.尝试
makeSomeType something = M.SomeType { M.something = []
, M.somethingElse = [something]
}
Run Code Online (Sandbox Code Playgroud)