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

  Write the definition of the function

Write the definition of the function, nodeCount, that returns the number of nodes in a binary tree. Add this function to the classbinaryTreeType and create a program to test this function.

  Creating flowchart of data found on employee time cards

Create a flowchart depicting the following situations: The data found on employee time cards are keyed onto a hard disk before they are processed by a computer.

  What is the current size of q

Suppose an initially-empty queue Q has performed a total of 32 enqueue operations, 10 front operations, and 15 dequeue operations, 5 of which generated QueueEmptyExceptions,

  The radar gun used by a police officer

The radar gun used by a police officer outputs a radar signal and measures the speed of the cars as they pass. However, when the officer wants to ticket an individual for speeding

  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.

  What is virtual memory

What is virtual memory and how is it related to the swap partition in Unix?

  What are the risks associated with the loss of these data

Based on the Ledford (2012) article, what special issues must be considered for corporate data which are not fully digitized? What are the risks associated with the loss of these data? What recovery procedures do you recommend for these situations..

  What are some ways that company''s can use to get the word

Security awareness programs are their so employees cannot make ignorance an excuse. What are some ways that company's can use to get the word out, and to make sure their employees cannot make that excuse?

  Display the name of the server as well as any cookie

Now try and see what happens if this variable is declared as a JSP scriptlet. c.Also display the name of the server as well as any cookie information that you can find.

  Structure stack that represents

Design a structure stack that represents a stack of elements of some arbitrary type. Include the functions: create(returns an empty stack), push(add an element to the top of the stack and return the resulting stack)

  Reason for problem encounter in deleting path variables

Discuss some of the problems he may soon encounter and explain the reasons for these problems. How could he easily return path to its original value?

  Most important components of a fully specified enterprise

What are the two most important components of a fully specified enterprise model? Describe the two basic approaches to designing an enterprise model.

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