【问题标题】:Haskell "not a visible field of constructor" errorHaskell“不是构造函数的可见字段”错误
【发布时间】:2011-07-12 12:38:48
【问题描述】:

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

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)

另一个模块.hs

module AnotherModule (makeSomeType) where

import qualified SomeModule as M

makeSomeType :: M.AnotherType -> M.SomeType
makeSomeType something = M.SomeType { something     = []
                                    , somethingElse = [something]
                                    }

【问题讨论】:

    标签: haskell constructor algebraic-data-types


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-10-21
      • 2012-07-21
      • 2012-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多