Question: Define a function called pow ( val pow = fn : int * int - > int ) that takes two integers as arguments and

Define a function called pow (val pow = fn : int * int -> int) that takes two integers as arguments and that returns the result of raising the first integer to the power of the second. You may assume that the power is not negative. For our purposes, we will assume that every integer to the 0 power is 1(this isn't true of 00, but that's okay).
Define a function called sumTo (val sumTo = fn : int -> real) that accepts an integer n and that computes the sum of the first n reciprocals. For example, sumTo(3) should return (1+1/2+1/3)=1.83333333.... The function should return 0.0 if n is 0. You may assume that the function is not passed a negative value of n.
Define a function called repeat (val repeat = fn : string * int -> string) that takes a string and an integer (>=0) as arguments and that returns a string composed of the given number of occurrences of the string. For example, repeat("hello",3) returns "hellohellohello", repeat("hello",0) returns "". You may assume that the function is not passed a negative value for the second argument.
Define a function called binary (val binary = fn: int -> string) that takes an integer n as an argument and returns a string corresponding to the 16-bit binary representation of that integer. For example, binary 17 returns "0000000000010001". You need not account for numbers whose binary representation requires more than 16 bits. Note: If needed, you can use the Int.toString function to convert integers to corresponding strings. You may find it helpful to write a helper function for this problem.
Define a function called countNegative (val countNegative = fn : int list -> int) that takes a list of integers as an argument and that returns a count of the number of negative integers in the list. For example, countNegative([3,17,~9,34,~7,2]) should return 2.
Define a function called absList (val absList = fn : (int * int) list ->(int * int) list) that takes a list of int * int tuples and that returns a new list of int * int tuples where every integer is replaced by its absolute value. For example, absList([(~38,47),(983,~14),(~17,~92),(0,34)]) should return [(38,47),(983,14),(17,92),(0,34)]. HINT: This is easier to solve if you write a helper function to process one tuple.
Define a function called split (val split = fn : int list ->(int * int) list) that takes a list of integers as an argument and that returns a list of the tuples obtained by splitting each integer in the list. Each integer should be split into a pair of integers whose sum equals the integer and which are each half of the original. For odd numbers, the second value should be one higher than the first. For example, split([5,6,8,17,93,0]) should return [(2,3),(3,3),(4,4),(8,9),(46,47),(0,0)]. You may assume that all of the integers in the list passed to the function are greater than or equal to 0.
Define a function called isSorted (val isSorted = fn : int list -> bool) that takes a list of integers and that returns whether or not the list is in sorted (nondecreasing) order (true if it is, false if it is not). By definition, the empty list and a list of one element are considered to be sorted.
Define a function called collapse (val collapse = fn : int list -> int list) that takes a list of integers as an argument and that returns the list obtained by collapsing successive pairs in the original list by replacing each pair with its sum. For example, collapse([1,3,5,19,7,4]) should return [4,24,11] because the first pair (1 and 3) is collapsed into its sum (4), the second pair (5 and 19) is collapsed into its sum (24) and the third pair (7 and 4) is collapsed into its sum (11).If the list has an odd length, the final number in the list is not collapsed. For example, collapse([1,2,3,4,5]) should return [3,7,5].
Define a function called insert (val insert = fn : int * int list -> int list) that takes an integer and a sorted (nondecreasing) integer list as parameters and that returns the list obtained by inserting the integer into the list so as to preserve sorted order. For example, insert(8,[1,3,7,9,22,38]) should return [1,3,7,8,9,22,38].
Define a function called decimal (val decimal = fn: string -> int) that takes a bit string corresponding to an integer and returns the decimal value of that integer. For example, decimal "10001" returns 17, decimal "001101" returns 13.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!