Question: Machine language excersises 4-13 Exercise 4 Write a function min3 of type int * int * int -> int that returns the smallest of three
Machine language excersises 4-13


Exercise 4 Write a function min3 of type int * int * int -> int that returns the smallest of three integers. Exercise 5 Write a function reds of type 'a * 'b' -> 'a * c that converts a tuple with three elements into one with two by eliminating the second element Exercise 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. . Exercise 7 Write a function cyclel 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, cyclel (1,2,3,4) should return [2,3,4,1). Exercise 8 Write a function sort3 of type real real real -> real list that returns a list of three real numbers, in sorted order with the small- est first. Exercise 9 Write a function de13 of type 'a list -> 'a list whose output list is the same as the input list, but with the third element deleted. Your function need not behave well on lists with lengths less than 3. Exercise 10 Write a function sqsum of type int -> int that takes a non-neg. ative integer n and returns the sum of the squares of all the integers 0 through n. Your function need not behave well on inputs less than zero. Exercise 11 Write a function cycle of type 'a list * int > 'a list that takes a list and an integer n as input and returns the same list, but with the first ele ment cycled to the end of the list n times. (Make use of your cyclei function from a previous exercise.) For example, cycle ([1,2,3,4,5,6), 2) should return the list (3,4,5,6,1,2]. Exercise 12 Write a function pow of type real + int -> real that raises a real number to an integer power. Your function need not behave well if the integer power is negative. Write a function max of type int list -> int that returns the largest element of a list of integers. Your function need not behave well if the list is empty. Hint: Write a helper function maxhelper that takes as a second parameter the largest element seen so far. Then you can complete the exercise by defining fun max x = maxhelper (tlx, hd x)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
