Thanks Vlatko ... 

That analogy helped .....  I created my own functor typeclass where i defined fmap :: MyFucntor f => (a->a) -> f a ->f a and that worked ... 


On Wed, Apr 2, 2014 at 7:24 PM, Vlatko Basic <vlatko.basic@gmail.com> wrote:
Try to visualize with concrete types


data Tree a = NULL | Node (Tree a) a (Tree a) deriving Show

Tree Int      = Node (Tree Int)       Int      (Node Int)       -- OK
Tree String = Node (Tree String) String (Node String)  -- OK

f :: Int -> String
f i = show i

and see what you get:


instance Functor Tree where
  fmap f NULL = NULL
  fmap f (Node left x right)                                                           -- Node (Tree Int)       Int      (Node Int)
    | (left  == NULL) && (right == NULL) = Node left (f x) right   -- Node (Tree Int)       String (Node Int)       === Not OK
    | (left  /= NULL) = Node (fmap f left) x right                            -- Node (Tree String) Int      (Node Int)       === Not OK
    | (right /= NULL) = Node left x (fmap f right)                           -- Node (Tree Int)      Int      (Node String)  === Not OK



-------- Original Message --------
Subject: [Haskell-beginners] Functor on Tree data constructor
From: Nishant <nishantgeek@gmail.com>
To: beginners@haskell.org
Date: 02.04.2014 12:53


instance Functor Tree where
............fmap f NULL = NULL
............fmap f (Node left x right) | (left  == NULL) && (right == NULL) = Node left (f x) right
................................................... | (left  /= NULL) = Node (fmap f left) x right
................................................... | (right /= NULL) = Node left x (fmap f right)


_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners




--
Nishant