haskell, Functor for Data Binary Tree

Viewed 1916

I am trying to write functor for Tree (form of this type is given below)

data Tree a = Empty | Node a (Tree a) (Tree a) 

instance Functor Tree where
    fmap f Empty = Empty
    fmap f (Node a x y) =  Node (f a) (fmap f x) (fmap f y)

It seems to be working, but what about more elegant (I am newbie in haskell) solutions? The second issue is that lecturer wrote signature: fmap :: (a -> b) -> f a -> f b for me, it is (a->b) -> Tree a -> Tree b, but it is not accepted by compiler ghci. Where is the point ?

2 Answers
Related