title: Standard ML binary tree type
body: <p>I'm studying ML in class and I've run into a homework problem I am stuck on. I've spent all day yesterday searching but made little progress and we did not talk about this in class, so I am hoping you guys can help me.</p>
  
  <p>We are given:</p>
  
  <pre><code>datatype which = STRING of string | INT of int
  </code></pre>
  
  <p>Part 1. We are told we need to create another datatype named <code>whichTree</code> for a binary tree containing the values of type <code>which</code> where data is only at the leaves of the tree.</p>
  
  <p>Part 2. We need to create a <code>whichSearch</code> function having type <code>whichTree -&gt; int -&gt; bool</code> returning true or false based on whether the int is in the tree.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>datatype which = STRING of string | INT of int;
  datatype whichTree = Empty | Node of int*whichTree*whichTree;
  
  val t1 = Node(6, Node(4,Empty,Empty), Node(15, Node(11,Empty,Empty), Node(24,Empty,Empty)));
  val t2 = Node(157,Empty,Empty);
  val t3 = Node(102,t1,t2);
  
  fun whichSearch (i, Empty) = false
  | whichSearch (i, Node(entry, left, right)) =
      if i = entry then true
      else whichSearch (i, left)
      orelse whichSearch (i, right);
  </code></pre>
  
  <p>The problem I am now facing is this:</p>
  
  <ol>
  <li>My <code>whichTree</code> does not contain the type <code>which</code>. I am not sure how I can fix that.</li>
  <li>I should have my <code>whichSearch</code> function of type <code>whichTree -&gt; int -&gt; bool</code> but it is <code>int * whichTree -&gt; bool</code> and am working on trying to figure out how to fix things. I am not sure how I would go about fixing this as I have to specify a value for <code>i</code> in <code>whichSearch</code> to search for. I'm searching on this but any tips would be great.</li>
  </ol>
  
  <p>Can anyone help? If so thank you! And thank you to the guys who already responded.</p>