I'm new to SML and trying to wrap my head around functional programming. I want to have a function that accepts a tree t and a character c and returns true or false if the tree contains the character.
The algorithm I want to implement is:
if leaf is null return false,
else if character is in leaf return true,
return result of left tree or result of right tree
This is my tree datatype
datatype 'a tree =
Leaf of 'a
| Node of 'a tree * 'a * 'a tree;
And this is the function
fun containsChar (Leaf t, c: char) = false
| containsChar (Node (left, t, right)) =
if t = c then true else false
| containsChar (Node (left, t, right)) = (containsChar left) <> (containsChar right);
I am getting Unbound value identifier "c". Why is this?