title: Binary tree monad implementation
body: <p>I have difficulties to understand how to correctly implement the (>>=) for the monad of binary tree. I have the following binary tree :</p>
  
  <pre><code>data BinTree a = Leaf a | Node a (BinTree a) (BinTree a) 
      deriving (Eq, Ord, Show, Read) 
  </code></pre>
  
  <p>Here's the (>>=) operator for my monad :</p>
  
  <pre><code>Node x l r &gt;&gt;= f = Node (f x) (l &gt;&gt;= f) (r &gt;&gt;= f)
                   __________^
  </code></pre>
  
  <p>I keep getting this error :</p>
  
  <pre><code>Couldn't match type `b' with `BinTree b'
  `b' is a rigid type variable bound by
    the type signature for
      &gt;&gt;= :: BinTree a -&gt; (a -&gt; BinTree b) -&gt; BinTree b
    at test.hs:153:5
   In the return type of a call of `f'
   In the first argument of `Node', namely `(f x)'
   In the expression: Node (f x) (l &gt;&gt;= f) (r &gt;&gt;= f)
  </code></pre>
  
  <p>So I don't understand how I can obtain a proper leaf of the correct type?</p>
  
  <p>Any help is appreciated</p>
  
  <p>Thanks</p>