Haskell错误“不在范围内:数据构造函数”

时间:2013-05-13 15:30:41

标签: haskell

我已经查看了有关此错误的其他帖子,我认为我没有犯这些错误。

不在范围内:数据构造函数'Extraction'。

Configuration.hs:

module Configuration
(Config
 , columns
 , headers
 , types
 , totals
 , extractions,
 Extraction
 , xState
 , xDivisions
 , xOffice
 ...) where

...

data Extraction = Extraction { xState     :: String
                             , xDivisions :: Maybe [String]
                             , xOffice    :: Maybe String } deriving Show


data Config = Config { columns     ::  String
                     , headers     :: [String]
                     , types       :: [String]
                     , totals      :: [String]
                     , extractions :: [Extraction] } deriving Show

...

PIF.hs:

module PIF (...) where

import Configuration

...

data Report = Report { division  :: String
                     , state     :: String
                     , office    :: String
                     , inSection :: Bool
                     , content   :: [String] } deriving Show

...

extract :: Config -> [Report] -> [Report]
extract c = filter f
  where f Report { division=d, state=s, office=o, inSection=_, content=_ } =
          map or $ map isMatch $ extractions c
          where isMatch
                  | Extraction { xState=xS, xDivisions=Just xD, xOffice=Nothing } = s==xS && (map or $ map (==d) xD)
                  | Extraction { xState=xS, xDivisions=Nothing, xOffice=Just xO } = s==xS && o==xO

如果您需要更多信息,请与我们联系。感谢。

以下是我更正的extract

extract c = filter f
  where f Report { division=d, state=s, office=o, inSection=_, content=_ } =
          or $ map isMatch $ extractions c
          where isMatch x =
                  case ((xDivisions x), (xOffice x)) of (Nothing, Just y) -> s==(xState x) && o==y
                                                        (Just y, Nothing) -> s==(xState x) && (or $ map (==d) y)

1 个答案:

答案 0 :(得分:14)

将导出行Extraction更改为Extraction(..)

如果没有它,您将导出类型而不是数据构造函数。由于您的类型和构造函数共享相同的名称,因此在这种情况下不太明显。