不在范围内:类型构造函数或类'ClientR'

时间:2015-07-27 23:07:22

标签: haskell

我正在尝试将包含某些数据类型的模块导入练习文件中 如下图所示:

--SimpleFunctions.hs
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE RecordWildCards #-}

module Chapter2.SimpleFunctions
    (
    ) where

data ClientR = GovOrgR { clientRName :: String }
            | CompanyR { clientRName :: String,
                        companyID :: Integer,
                        person :: PersonR,
                        duty :: String}
            | IndividualR {person :: PersonR, ads :: Bool }
            deriving(Show)

data PersonR = PersonR {  firstName :: String,
                        lastName :: String,
                        gender :: Gender }
                        deriving(Show)

--exercise.hs
import Chapter2.SimpleFunctions

filterGovOrgs :: [ClientR] -> [ClientR]
filterGovOrgs xs = xs

项目树结构如下:

.
├── ProjectApproachBook.cabal
├── Setup.hs
├── chapter2
│   ├── Section2
│   │   └── Example.hs
│   └── SimpleFunctions.hs
├── chapter3
│   └── exercise.hs
└── dist

当我在ghci中加载exercise.hs时,我收到错误:

  

不在范围内:输入构造函数或类'ClientR'

Prelude > :l chapter3/exercise.hs 
[1 of 2] Compiling Chapter2.SimpleFunctions ( Chapter2/SimpleFunctions.hs, interpreted )
[2 of 2] Compiling Main             ( chapter3/exercise.hs, interpreted )

chapter3/exercise.hs:53:19:
    Not in scope: type constructor or class ‘ClientR’

chapter3/exercise.hs:53:32:
    Not in scope: type constructor or class ‘ClientR’
Failed, modules loaded: Chapter2.SimpleFunctions.

1 个答案:

答案 0 :(得分:4)

问题是第2章没有公开ClientR .SimpleFunctions模块:

module Chapter2.SimpleFunctions
    (ClientR
    ) where