I created a Tree structure in a file called Tree2.hs
module Tree2
(
Tree
) where
data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show)
then I imported it and tried to use it as an instance of a class
import qualified Tree2
class YesNo a where
yesno :: a -> Bool
instance YesNo (Tree2.Tree a) where
yesno EmptyTree = False
yesno _ = True
But I'm getting this Error when loading it in ghci:
Not in scope: data constructor ‘EmptyTree’
Failed, modules loaded: Tree2.
Anyone know why?
First,
only exports the
Tree
data type, not its constructors; you should useinstead.
Second, as you're doing a qualified import, you need to use
Tree2.EmptyTree
instead of justEmptyTree
.