i want to find the number of occurrences of some number in any tree.And here is my code but it gives an error which i can not find why it happens.
data Tree a = Empty | Node (a ,Tree a,Tree a) deriving (Show)
occurst _ Empty = 0 -- this line occurs error
occurst a ( Node (x,left,right) ) = if x==Empty then 0
else if a==x then 1 + (occurst a left) + (occurst a right)
else (occurst a left) + (occurst a right)
j=let t = Node (3 , Node (2 , Node (1 , Empty , Empty ) , Node (1 , Empty , Empty )),Node (1 , Node (2 , Node (1 , Empty , Empty ) , Node (1 , Empty , Empty )),Node (1,Empty,Empty)))
in occurst 1 t
Error message is that:
ERROR "treeExample.hs":95 - Cannot infer instance
*** Instance : Eq (Tree a)
*** Expression : occurst
INput Outputs must be :
occurst 1 t -> 6
occurst 2 t -> 2
occurst 3 t ->1
occurst 4 t ->0