(* lecture 10: more data types; datatype Gender = Male | Female; (* Produces the cost of a haircut for a person of the given gender and age. Kids' under 10 haircuts are $10; for adults, men cost $18.25 and women cost $36.50. *) fun haircutPrice(age, gender) = if age < 10 then 10.00 else 18.25 * (case gender of Male => 1.0 | Female => 2.0); (* Coffee : type, caffeinated? Wine : label, year Beer : brewery name Water : needs no parameters *) datatype Beverage = Water | Coffee of string * bool | Wine of string * int | Beer of string; (* Produces cafe's price for the given drink. *) fun price(Water) = 1.50 | price(Coffee(type, caf)) = if caf then 3.00 else 3.50 | price(Wine(label, year)) = if year < 2009 then 30.0 else 10.0 | price(Beer(_)) = 4.00; (* A type to represent binary search trees of integers. *) datatype IntTree = Empty | Node of int * IntTree * IntTree; (* Adds the given value to the tree in order. Produces/returns the new state of the tree node after the add. *) fun add(Empty, value) = Node(value, Empty, Empty) | add(Node(data, left, right), value) = if value < data then Node(data, add(left, value), right) else Node(data, left, add(right, value)); (* Produces the height of the given tree. An Empty tree has a height of 0. *) fun height(Empty) = 0 | height(Node(_, left, right)) = 1 + Int.max(height(left), height(right));