2013-05-13 96 views
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) 
+0

此錯誤還涵蓋了我在表達式上下文中使用模式語法的事實。我將'Extraction {xState = xS ...}'更改爲'case'語句。我還通過'或'刪除了不正確的'地圖'。 '或'減少了一個列表,它不會映射它。 – 2013-05-13 19:44:44

回答

14

更改線路出口ExtractionExtraction(..)

如果沒有這種情況,您正在導出類型而不是數據構造函數。由於您的類型和構造函數共享相同的名稱,在這種情況下,這不明顯。

+0

聖牛!非常感謝!我從來不會想到我自己。 :) – 2013-05-13 17:53:59