// // This file is for Assignment 4, BU CAS CS 520, Fall, 2008 // // Instructor: Hongwei Xi (hwxi AT cs DOT bu DOT edu) // (* ****** ****** *) datatype gtree (a:t@ype) = | E (a) of () | B (a) of (a - gtree a) // end of [datatype gtree] fun leftGtree (t: gtree bool): gtree bool = case+ t of | B (ft) => let val ft = ft: bool - gtree bool in ft (true) end // end pf [B] | E () => E () // end of [leftGtree] fun rightGtree (t: gtree bool): gtree bool = case+ t of | B (ft) => let val ft = ft: bool - gtree bool in ft (false) end // end pf [B] | E () => E () // end of [rightGtree] fun printGtree (t: gtree bool): void = case+ t of | B ft => let val ft = ft: bool - gtree bool in print "B("; printGtree (ft true); print ", "; printGtree (ft false); print ")" end // end of [B] | E () => print "E" // end of [printGtree] val t1 = E () val t2 = B {bool} (lam _ => E ()) val t3 = B {bool} (lam b => if b then t1 else t2) val () = (print "t3 = "; printGtree t3; print_newline ()) val t4 = leftGtree (t3) val () = (print "t4 = "; printGtree t4; print_newline ()) val t5 = rightGtree (t3) val () = (print "t5 = "; printGtree t5; print_newline ()) (* ****** ****** *) implement main () = () (* ****** ****** *) (* end of [gtree.dats] *)