title: Deletion in Binary Search Tree in OCaml
body: <p>i am constructing the operations of <code>binary search tree</code> in OCaml.</p>
  
  <pre><code>type ('a, 'b) bst = 
    | Node of 'a * 'b * ('a, 'b) bst * ('a, 'b) bst
    | Leaf;;
  
  let rec insert k v = function
    | Leaf -&gt; Node (k, v, Leaf, Leaf)
    | Node (k', v', left, right) -&gt;
      if k &lt; k' then Node (k', v', insert k v left, right)
      else if k = k' then Node (k, v, left, right)
      else Node (k', v', left, insert k v right);;
  
  let rec delete k = function
    | Leaf -&gt; Leaf
    | Node (k', v, l, r) as p -&gt;
      if k &lt; k' then Node (k', v, (delete k l),r)
      else if k &gt; k' then Node (k', v, l, (delete k r))
      else 
      match (l, r) with
        | (Leaf, Leaf) -&gt; Leaf
        | (l, Leaf) -&gt; l
        | (Leaf, r) -&gt; r
        | (_, _) -&gt;
          let Node (km, vm, _, _) = max l in
          Node (km, vm, delete km l, Leaf)
  </code></pre>
  
  <p><strong>Can anyone tell me whether my <code>deletion</code> code is good enough or any improvement?</strong></p>