gpt4 book ai didi

Haskell 错误 "Not in scope: data constructor"

转载 作者:行者123 更新时间:2023-12-04 10:19:04 25 4
gpt4 key购买 nike

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

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

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

最佳答案

更改导出行ExtractionExtraction(..) .

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

关于Haskell 错误 "Not in scope: data constructor",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16525803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com