This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: # let fact2 x = let rec helper (n,r) = match n with 0 > r  _ > helper ((n1),(x*r)) in helper (x,1) ;; # let rec add1 (n,y) = match n with 0 > y  _ > 1 + add1 (n1,y) ;; # let rec add2 (n,y) = match n with 0 > y  _ > add2 (n1,y+1); Problem 3: Write the following functions on trees described using the datatype Tree shown in Problem 1. • depth : Tree > int where the depth of a leaf is 0 and the depth of an internal node is 1 greater than the maximum depths of its children. • size : Tree > int which computes the number of leaf nodes of a tree. • sum : Tree > int which adds up the values of all the leaves of the tree • isLeaf : Tree * int > bool which given a tree and an integer returns true if and only if the integer appears in a leaf of the tree. • duplicate : Tree > bool which given a tree returns true if and only if the tree has two distinct leaves with the same value....
View
Full
Document
This note was uploaded on 03/16/2010 for the course CSE 101 taught by Professor Staff during the Winter '08 term at UCSD.
 Winter '08
 staff

Click to edit the document details