I am trying to define my tree and create a search function, but I think I am getting lost in the syntax of SML. Here is my tree
datatype either = ImAString of string | ImAnInt of int;
datatype eitherTree = Empty
| eLEAF of either
| eINTERIOR of (either*eitherTree*eitherTree);
This is my search function
fun eitherSearch (eLEAF(v)) x = false
| eitherSearch (eINTERIOR(ImAnInt(v), lt, rt)) x =
if x < v then eitherSearch lt v
else if x > v then eitherSearch rt v
else true;
And this is how I defined my tree
val T2 = eINTERIOR(ImAnInt(4), eLEAF(ImAnInt(1), eLEAF(ImAnInt(2), Empty, Empty), Empty), eINTERIOR(ImAnInt(3), Empty, Empty));
This returns
val T2 =
eINTERIOR
(ImAnInt 4,eINTERIOR (ImAnInt #,eINTERIOR #,Empty),
eINTERIOR (ImAnInt #,Empty,Empty)) : eitherTree
I'm guessing this isn't correct because those # symbols don't make sense. Is there a better way to define the tree so that it works in the search function? When I define a smaller tree like
val T1 = eINTERIOR(ImAnInt(5), eLEAF(ImAnInt(4)), eLEAF(ImAnInt(6)));
The search function works correctly, but in T2 I don't think I'm understanding how to write mult layered trees.