The functions square and double take a single int parameter

Assignment Help Basic Computer Science
Reference no: EM13313508

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 <comparision in your origional function.

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.

Reference no: EM13313508

Questions Cloud

Define conjugate acid-base pairs to use in the preparation : Select all of the following that would be acceptable conjugate acid-base pairs to use in the preparation of a pH=9.8 buffer.
Evaluate an infix expression entered by the user : Spaces between tokens are allowed but not required. The program will repeatedly prompt the user for the value of x, displaying the value of the expression each time. When the user enters the letter q instead of a number, the program terminates.
What is the magnitude of torque : a person exerts force of 35n on the end of an door 88 cm wide, what is the magnitude of torque if the force is exerted perpendicular to the door
Which have user profiles that are available for transfer : Which have user profiles that are available for transfer?
The functions square and double take a single int parameter : 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) evaluate..
Provide kitchen staff with the functionality to display orde : Owners and managers have the ability to keep track of the inventories, quantities and item prices with additional functionality which allows for future orders to be implemented as required.
Construct an annotated bibliography : Construct an annotated bibliography - Are corporations obliged to help combat social problems or is factory farming morally justifiable?
How much information is available to potential hackers : Maintaining a proactive approach on security requires that an organization perform its own hacking footprinting to see how much information is available to potential hackers
Calculate the youngs modulus of this tendon : A 14.4 cm long tendon was found to stretch 3.79 mm by a force of 11.1 N. Calculate the Young's modulus of this tendon

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Display the total annual compensation

A salesperson will continue to earn a fixed salary of $50,000. The current sales target for every salesperson is $80,000.

  Find the error in the following pseudocode

Find the error in the following pseudocode

  Type and topology of lan

Type and topology of LAN

  What is the copy constructor for a weighted digraph in c++

What is the copy constructor for a weighted digraph in c++?

  Explain computer etiquette for effective communication

Each day we should be careful to insure that personal information is not compromised. Computer etiquette is difficult for effective communication.

  Making the row number absolute

In cell F6, create a formula to calculate the Total with Insurance. Multiply E6 by 1+ the insurance to calculate the result. Enter the insurance rate as a mixed cell reference in the formula, making the row number absolute.

  What are techniques to use in planning presentation

You prepared and distributed a system requirements document, and you anticipate some intense questioning at the meeting. When planning your presentation, what are some techniques you will use?

  True and false

A.  (True | False) In the MSP430's active mode, the MCLK and SMCLK clocks are up and running and ACLK is not running (it is turned off).

  What is the role of the project manager

What other additional information would you like to share with the class?

  Ways to send these postcards to friends

There are k types of postcards, each with limited amount. Let there be ai copies of i-th postcard. How many ways are there to send these postcards to n friends?

  Decide which of the following identifier forms

Decide which of the following identifier forms is most readable, and then support the decision. SumOfSales Sum_of_sales SUMOFSALES

  Use the method of iteration to find a formula

Use the method of Iteration to find a formula expressing S(n) as a function of n for the given recurrence relation and initial condition

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd