title: Binary search tree preorder algorithm in OCaml
body: <p>I am having trouble implementing this algorithm in OCaml since I must print parentheses in between the function.</p>
  
  <p>The algorithm goes like this:</p>
  
  <pre><code>BEGIN
     WRITE ( "(" )
     IF (NOT EMPTY tree) THEN 
        IF (NOT EMPTY (left_leaf tree)) OR (NOT EMPTY (right_leaf tree)) THEN BEGIN
          WRITE (" ", root tree, " ")
          preorder (left_leaf tree)
          WRITE (" ")
          preorder (right_leaf tree)
        END ELSE
          WRITE (" ", root tree, " ")
     WRITE ( ")" ); {this has to be always executed}
  END
  </code></pre>
  
  <p>This is my poor attempt in OCaml:</p>
  
  <pre><code>let rec preorderParenthesed tree = 
  
     print_string "(" in
     if not (isEmptyTree tree) then (
        if not (isEmptyTree(leftLeaf tree)) || not (isEmptyTree(rightLeaf tree)) then begin
          print_string " ";
          print_string (string_of_root (root tree));
          print_string " ";
          preorderParenthesed (leftLeaf tree);
          print_string " ";
          preorderParenthesed (rightLeaf tree);
        end else
          print_string " ";
          print_string (string_of_root (root tree));
          print_string " "; 
      ) 
      else if true then print_string ")\n";;
  </code></pre>
  
  <p>Any help would be appreciated</p>
  
  <pre><code>type bst = 
  Empty   
  | Node of (key * bst * bst);;
  </code></pre>