title: Pointer to a record in OCaml
body: <p>I am implementing binary search trees in OCaml, trying to use as much imperative programming as possible.</p>
  
  <p>I have the following data type:</p>
  
  <pre><code>type tKey = Key of int;;
  
  type tBST = Null | Pos of node ref
              and node = {mutable key : tKey; mutable left : tBST; mutable right : tBST};;
  </code></pre>
  
  <p>I am having trouble with this function:</p>
  
  <pre><code>let createNode k tree = 
      tree := Pos ({key = k; left = Null; right = Null});;
  
  Error: This record expression is expected to have type node ref
         The field key does not belong to type ref
  </code></pre>
  
  <p>A binary search tree can be either Null (means empty tree) or a Pos. A tree Pos is a pointer to a node, and a node is a structure of a key and 2 other trees (left and right).</p>
  
  <p>My main goal here is to have a tree that is modified after functions are over. Passing tree by reference so when createNode is over, the tBST I passed as parameter is modified.</p>
  
  <p>Question: is actually possible to do what I am trying in OCaml? if so, how could I change my function createNode and/or data type to make this happen? </p>
  
  <p>Thank you very much.</p>