(******* 5.1 *******) (* Write a function cube of type int -> int that returns the cube of its parameter. *) fun cube x = x * x * x; cube 0; cube ~1; cube 2; (****** 5.2 *******) (* Write a function cuber of type real -> real that returns the cube of its parameter. *) fun cuber(x:real):real = x*x*x; cuber 0.0; cuber ~1.0; cuber 5.3; (****** 5.3 *******) (* Write a function forth of type 'a list -> 'a that returns the fourth element of a list. Your function need not behave well on lists with less than four elements. *) fun fourth (L) = hd (tl (tl (tl L))); fourth [1, 2, 3, 4, 5]; fourth ["abc", "def", "gggg", "hhhh", "iiii", "j", "k"]; (****** 5.4 *******) (* Write a function min3 of type int * int * int -> int that returns the smallest of three integers. *) fun min3 (a, b, c) = if a < b andalso a < c then a else if b 'a * 'c that converts a tuple with three elements into one with two by eliminating the second element. *) fun red3 (a, b, c) = (a, c); (****** 5.6 *******) (* Write a function thirds of type string -> char that returns the third character of a string. Your function need not behave well on strings with lengths less than 3. *) fun thirds (s) = hd (tl (tl (explode s) ) ); thirds("123456"); thirds("789"); (******* 5.7 *******) (* Write a function cycle1 of type 'a list -> 'a list whose output list is the same as the input list, but with the first element of the list moved to the end. For example, cycle1 [1, 2, 3, 4] should return [2, 3, 4, 1]. *) fun cycle1(L) = if null L then L else tl(L) @ [ hd (L) ];