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

  Decision regarding which computer to purchase

Decide what factors are significant in your decision as to which computer to purchase and write them. After you choose the system you would like to buy, recognize which terms refer to hardware and which refer to software.

  Describe an algorithm

Describe an algorithm for determining if a given list contains a cycle using only constant additional space. The runtime should be O(N), where N is the (unknown) number of elements in the list. (Hint: use two iterators that advance at different sp..

  How to solve performance problem of computer

Your friend recommends upgrading RAM to 256 MB to correct performance problems. Is there any other way to solve performance problem? Justify your answer.

  Calculate and display height and cost of container

Compute and display the height and cost of the container. Use the following formulas, where V is the volume, r is the radius, h is the height, and C is the cost.

  Write a program that implements binary search first using

To understand the value of recursion in a programming language write a program that implements binary search first using recursion and without recursion.

  Describe how to recover file for further investigation

When you try to open file in image viewer, message is displayed indicating that file is corrupt. Write 2-3 page report describing how to recover the file, orkty.zip, for further investigation.

  Explain how engineers be assigned to maximize sales

A sales manager has 3 areas and 5 sales engineers. If assignment of sales engineers to areas will result in expected sales as shown, how must engineers be assigned to maximize sales?

  Class templates are typically used to replace overloaded

1.How would you overload the comparison operators == and !=? What is the format to overload these operators? 2. Class templates are typically used to replace overloaded functions. Can you compare the two?

  What is ldap and what are its security vulnerabilities

Why do you think an organization would continue to use directory services that have known security flaws?

  Sketch the input and output timing waveforms

For a 3-to-8 decoder with high outputs and an active high enable line (EN): a) List the truth table: b) write the boolean equations: c) sketch the input and output timing waveforms for all input combinations.

  Why motherboard sometimes support more than one speed

Why does motherboard sometimes support more than one system bus speed? So that it can support different processors running at different speeds.

  Compute the fraction of time mary spends using her telephone

Assuming a single-server limited-capacity Bernoulli queuing process with 1-minute frames, compute the fraction of time Mary spends using her telephone.

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