The functions square and double take a single int parameter


Functions can be passed as parameters just like other values in ML.For example, consider these function definitions:

fun sqaure a = a * a;

fun double a = a + a;

fun compute (n,f) = f n;

The functions square and double take a single int parameter and return an int result.The function compute takes a value n and a function f, and returns the result of calling that function f with n as its parameter.So, compute(3,square) evaluates to 9, and compute(3,double) to 6.

* Make another version of quicksort function, but this time of type 'a list * ('a * 'a -> bool) -> 'a list. The second parameter should be a function that performs the role of the
Why would you want to define a function? because it is much more useful than the origional one. For example, suppose you define icmp and rcmp like this:

fun icmp (a, b) = a < b;

func rcmp ( a : real, b) = a < b;

You should now use quick sort(L, icmp) to sort an integer list L, and you could use quicksort(M, rcmp) to sort a real list M. and if you defined: fun ircmp(a,b) = a > b;

then you could use quicksort(L, ircmp) to sort the integer list L in reverse order.

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: The functions square and double take a single int parameter
Reference No:- TGS0652188

Expected delivery within 24 Hours