Hi!
When I was trying to sleep last night I though I could implement Search Trees
in Haskell.
And not only that, I would try to implement them as monads.

The problem is that search trees require context Ord a.

What I want is something like the following:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
module SearchTree where

data Ord a => SearchTree a = Empty
                           | T a (SearchTree a) (SearchTree a) 

instance Monad SearchTree where

  (T a l r) >>= f = (f a) ++ (l >>= f) ++ (r >>= f)
  Empty     >>= f = Empty

  return a = T a Empty Empty

instance MonadZero SearchTree where
  zero = Empty

instance MonadPlus SearchTree where
  Empty     ++ x                   = x
  x         ++ Empty               = x
  (T a l r) ++ y@(T b _ _) | b > a = T a l (r ++ y)
                           | True  = T a (l ++ y) r
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Since Ord a is required for SearchTree a, I would want this to work.

Does anyone know if this is possible to do in Haskell?

Please reply by mail directly to me as well.

        n.

-----[ norpan ]---------[ [EMAIL PROTECTED] ]--------[ martin norb{ck ]-----
-----[ please be noted that the { is really a swedish letter but it is ]-----
-----[ unrepresentable in ascii. in iso8859-1 it looks like this: "a". ]-----




Reply via email to