Sprawdziłem inne posty dotyczące tego błędu i nie sądzę, że popełniam któryś z tych błędów.Błąd Haskella "Nie w zakresie: konstruktor danych"
Nie w zakresie: konstruktor danych "Ekstrakcja".
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
Daj mi znać, jeśli potrzebujesz więcej informacji. Dzięki.
Tu jest moja poprawione 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)
Ten błąd obejmował również fakt, że używałem składni wzorca w kontekście wyrażenia. Zmieniłem 'Extraction {xState = xS ...}' na instrukcję 'case'. Usunąłem także niepoprawne 'map's over' lub'. 'lub 'zmniejsza listę, nie mapuje nad nią. –