Đã Đóng

OCAML.....

The purpose of this project is for you to show that you can write elementary phrases in OCaml, especially phrases involving pattern matching and recursion.

A most important feature to watch, as you work on your computer, is the type inference performed by the OCaml system.

Anyway, you are to write OCaml code for the following:

1. a function that takes a list as argument, and that returns the value 1 if the list is empty, the value 2 if the list is of cardinality 1, and the value 0 if the list is of cardinality 2 or higher

(hint: use pattern matching)

2. a function to rotate a list, removing the head element if any, and placing it at the end

(hint: use pattern matching, and list concatenation @)

3. a function to remove the last element in a list, if any

(hint: use pattern matching, and possibly the [login to view URL] function that reverses a list)

4. a function to remove all occurrences of an element y from a list

(hint: use pattern matching and recursion; if..else may be used too)

5. a function that counts how many 0 and 1 there are in a list of integers (hint: use pattern matching and recursion)

6. a function, called makepairs, that takes an int x and a list of ints [a;b;c;,…] as arguments, and that produces the list of pairs [ (x,a); (x,b); (x,c); ….]

7. a function to compute, without explicit factorials, the binomial coefficients (hint: use pattern matching and recursion; use an appropriate formula for binomial coefficients; you need to use the recursive formula for binomial coefficients, from Discrete Math)

8. a function dup on lists that takes a list such as [a;b;c;d] as argument, and produces [a;a;b;b;c;c;d;d]

(hint: use pattern matching and recursion)

9. a function undup that acts as the inverse of dup; the function should throw an exception

if the argument given is not a list obtained by a dup

(hint: use pattern matching and recursion; a nested match may be used as well;

recall that throwing an exception is just a matter of saying something like raise (Failure "bad input") )

10. a function that finds the smallest element in a list (hint: use pattern matching and recursion;

raise (Failure "Empty list") if the list is empty;

there is already a min function that computes the smaller of 2 numbers)

Note: Do run test your functions in the OCaml toplevel, in your Ubuntu, for example.

Kĩ năng: XAML

Xem nhiều hơn: project is to develop a filesystem and the functions that control access to and manipulation of the filesystem there are two par, explain the purpose of a managing agent preparing a financial statement for the landlord of a managed property, the site url property of the project does not contain a valid url to ensure that designers work as expected set the site url pro, what is the purpose of a resume, what is the purpose of a sequence diagram, what is the purpose of a use case diagram, what is the purpose of a w9 form, what is the purpose of a writing rubric, The objective of the this project is to deliver a complete system that aims at performing vibration analysis of a target moving , The main objective of this project is to design a multivariable state feedback roll bite controller to maintain a desired thickn, The final project is to develop a master facility plan of Port of Beaumont.  1. Introduction  2. Existing port facilities a, The final project is to develop a master facility plan of Port of Beaumont., a guide to the manhattan project in washington state, who do you hire as a technical writer for the new project? quizlet, what is the purpose of enabling learn as the action on a firewall policy, the purpose project book, the purpose project, the purpose project ideo, what is the innocence project and why is it important, what is the purpose of a project

Về Bên Thuê:
( 0 nhận xét ) Macomb, United States

ID dự án: #31553666