
2 Apr
2014
2 Apr
'14
11:12 a.m.
Hi Nishant,
fmap f (Node left x right) | (left == NULL) && (right == NULL) = > Node left (f x) right
The function 'f' maps from 'a -> b' and 'left' and 'right' have the type 'Tree a', by not mapping 'left' and 'right' with 'f', you're telling the compiler that the types 'a' and 'b' are equal, but the compiler doesn't consider these types to be equal. You also have to map 'left' and 'right': instance Functor Tree where fmap f NULL = NULL fmap f (Node left a right) = Node (fmap f left) (f a) (fmap f right) Greetings, Daniel