Haskell“不是构造函数的可见字段”错误

发布于 2024-10-21 04:53:49 字数 1129 浏览 5 评论 0原文

我收到一个我不太明白的错误:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风轻花落早 2024-10-28 04:53:49

somethingsomethingElse 基本上是在 SomeModule 中定义的函数。尝试

makeSomeType something = M.SomeType { M.something     = []
                                    , M.somethingElse = [something]
                                    }

something and somethingElse are basically functions defined in SomeModule. Try

makeSomeType something = M.SomeType { M.something     = []
                                    , M.somethingElse = [something]
                                    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文