I've defined a haskell data type with constructors and a type synonym for it.I'm not able to use its data constructors.
Type definition :
module BinaryTreeModule(BinaryTree,..) where
data BinaryTree a = Empty | Node (BinaryTree a) a (BinaryTree a)
type synonym:
import BinaryTreeModule(BinaryTree)
type BST = BinaryTree
usage:
insert :: a -> BST a -> BST a
insert _ Empty = ...
insert _ Node .. = ...
I'm getting an error saying Empty and Node constructors not found.
I've also defined them in different files. If BST is just a synonym for BinaryTree shouldn't their constructors be the same ?
Also is there a better way to "inherit" the BinaryTree type to different types? Are typeclasses the correct solution here?
Edit: added how I'm importing between files
EmptyandNodeconstructors from your BinaryTree module? - Chad Gilbertimport MyModule(BinaryTree)vs.import MyModule(BinaryTree(..))- also note thatimport MyModule(BST)is the same as the first! - Random Devimport MyModule(BinaryTree). How do i import the data constructors i.e. BinaryTree(..) - VigneshMlensandpipesand probably elsewhere where they're valuable, but in typical circumstances, you probably just shouldn't use them. GHC's type families are much more often useful, but they're a more advanced feature. - dfeuer