VigneshM
VigneshM

Reputation: 157

Haskell no data constructors for type synonym

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

Upvotes: 0

Views: 229

Answers (1)

VigneshM
VigneshM

Reputation: 157

After @Carsten's comment, I realised I'm not importing the constructors from the module

import BinaryTreeModule(BinaryTree(Empty,Node)) fixed the issue

Upvotes: 2

Related Questions