Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Error "Not in scope: data constructor"

Tags:

haskell

I've reviewed the other posts on this error, and I don't think I'm making any of those mistakes.

Not in scope: data constructor '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

Let me know if you need more information. Thanks.

Here is my corrected 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)
like image 902
Jeff Maner Avatar asked May 13 '13 15:05

Jeff Maner


1 Answers

Change the export line Extraction to Extraction(..).

Without that, you're exporting the type but not the data constructor. Since your type and constructor share the same name, this is less than obvious in this case.

like image 70
sclv Avatar answered Sep 18 '22 12:09

sclv