importing haskell module says "not in scope"

1.5k Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

First,

module Tree2
(
 Tree
) where

only exports the Tree data type, not its constructors; you should use

module Tree2
(
  Tree(..)
) where

instead.

Second, as you're doing a qualified import, you need to use Tree2.EmptyTree instead of just EmptyTree.