
23 Jul
2011
23 Jul
'11
6:37 a.m.
2011/7/23 Александр
Hello,
I built binary tree with:
data Tree a = Empty | Node a (Tree a) (Tree a) deriving (Eq, Ord, Read, Show) How can i make Monad type class instance for this tree? And can i make it on not?
i try:
instance Monad Tree where return x = Node x Empty Empty Empty >>= f = Empty (Node x Empty Empty) >>= f = f x
1) Do you really need a Monad instance for this? 2) One possibility is just have it being (Node x _ _) >>= f = f x -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com