(* ----- From Section 1.12 ----- *) (* Examples with numbers *) fun factorial(0) = 1 | factorial(n) = n * factorial(n-1); (* Ex 1.12.4. Homemade multiply *) fun multiply(x, 0) = 0 | multiply(x, y) = x + multiply(x, y-1); (* Ex 1.12.6. Summation. *) fun sum(1) = 1 | sum(n) = n + sum(n-1); (* Examples with strings *) fun capitalizeAll("") = "" | capitalizeAll(s) = str(Char.toUpper(String.sub(s, 0))) ^ capitalizeAll(substring(s, 1, size(s) - 1)); (* 1.12.2. Reverse a string. *) fun reverse("") = "" | reverse(s) = reverse(substring(s, 1, size(s) -1)) ^ str(String.sub(s, 0)); (* 1.12.8. --- Homework *) (* The book doesn't say what to name the function, but the grading system expects the name "fib" (not "fibonacci"). Also index the Fibonacci sequence starting at 0 (0 is the 0th Fibonacci number). *) fun fib(0) = | fib(1) = | fib(n) =