[Haskell-beginners] Functor on Tree data constructor
Daniel Trstenjak
daniel.trstenjak at gmail.com
Wed Apr 2 11:12:09 UTC 2014
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
More information about the Beginners
mailing list