In the following three questions, use the following definition of the tree datatype.
datatype tree = Leaf of int | Node of tree * tree
fun get (Leaf N) = N | get (Node(left,right)) = let val (x,y) = (get left, get right) in if x > y then x else y end;What function does get compute? Pick only one answer.
fun f (Leaf n) = [n] | f (Node(left,right)) = (f right) @ (f left);
fun multup (Leaf n) = n | multup (Node(left, right)) = (multup left) * (multup right);This function will sum up all the integers labeling leaves in the input tree. Write a new function, called opup similar to this function except that it has type
(int * int -> int) * tree -> intand where the first argument to opup is to be used instead of the times (*). For example, if T denotes a tree, then the expressions (multup T) and (opup (op *, T) should always be the same value, and where opup(op +, T) returns the sum of the numbers labeling leaves, and where opup(max, T) picks the largest integer labeling leaves (where max is a function from a pair of integers to the maximum of those integers).
fun opup (Op, (Leaf n)) = n | opup (Op, (Node(left, right))) = Op(opup(Op, left), opup (Op, right));