2015-06-14 31 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