2015-06-14 91 views
2

我在一个叫Tree2.hs进口哈斯克尔模块写着“不在范围内”

module Tree2 
(
Tree 
) where 

data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show) 

文件创建的树结构,那么我进口它,并试图使用它作为一个类的实例

import qualified Tree2 

class YesNo a where 
    yesno :: a -> Bool 

instance YesNo (Tree2.Tree a) where 
    yesno EmptyTree = False 
    yesno _ = True 

Not in scope: data constructor ‘EmptyTree’ 
Failed, modules loaded: Tree2. 

谁知道为什么:

但在ghci中加载它,当我得到这个错误?

回答

11

首先,

module Tree2 
(
Tree 
) where 

仅导出Tree数据类型,而不是它的构造;您应该使用

module Tree2 
(
    Tree(..) 
) where 

改为。

其次,由于您正在执行合格的导入,因此您需要使用Tree2.EmptyTree而不是仅仅使用EmptyTree