Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell “哈斯克尔错误”;不在范围内:数据构造函数“;_Haskell - Fatal编程技术网

Haskell “哈斯克尔错误”;不在范围内:数据构造函数“;

Haskell “哈斯克尔错误”;不在范围内:数据构造函数“;,haskell,Haskell,我已经回顾了关于这个错误的其他帖子,我认为我没有犯任何错误 不在范围内:数据构造函数“提取” 配置.hs: module Configuration (Config , columns , headers , types , totals , extractions, Extraction , xState , xDivisions , xOffice ...) where ... data Extraction = Extraction { xState ::

我已经回顾了关于这个错误的其他帖子,我认为我没有犯任何错误

不在范围内:数据构造函数“提取”

配置.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 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)

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


否则,您将导出类型,而不是数据构造函数。由于您的类型和构造函数共享相同的名称,因此在本例中这一点并不明显

天哪!非常感谢你!我自己永远也不会想到这一点。:)这个错误还包括我在表达式上下文中使用模式语法的事实。我将
Extraction{xState=xS…}
更改为
case
语句。我还删除了
上不正确的
映射<代码>或
减少列表,但它不会映射到列表上。