[Haskell-cafe] Monad for binary tree data structure
Ivan Lazar Miljenovic
ivan.miljenovic at gmail.com
Sat Jul 23 08:37:39 CEST 2011
2011/7/23 Александр <kommunist1917 at mail.ru>:
> 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 at gmail.com
IvanMiljenovic.wordpress.com
More information about the Haskell-Cafe
mailing list