7
我回顧了關於這個錯誤的其他文章,我不認爲我犯了這些錯誤。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)
此錯誤還涵蓋了我在表達式上下文中使用模式語法的事實。我將'Extraction {xState = xS ...}'更改爲'case'語句。我還通過'或'刪除了不正確的'地圖'。 '或'減少了一個列表,它不會映射它。 – 2013-05-13 19:44:44