Homework Problems for June 10 lecture:
- Write an OCaml function
curry
that curries a function. - Write an OCaml function
uncurry
that uncurries a function. - Write an OCaml function that takes a string, treats it as a base 256 numeral, and returns the
int
that it corresponds to. - Write an OCaml that converts an integer to the string giving the base 256 numeral.
- Write an OCaml that takes an integer and a base and returns the list of digits in that base, each digit represented as an integer.
- Write an OCaml function that takes a natural number, and if it has the form of a list of natural numbers, returns the OCaml list.
- Write an OCaml function that takes computes the value of the serial pair
- Write an OCaml function that takes two functions of type
:int -> int
and returns the composite of the two functions:composite f g
- Show on paper that the composites
composite curry uncurry
andcomposite uncurry curry
are both the identity. - Describe an injective function from the set of finite sets of natural numbers to the set of natural numbers.
Implement this function in OCaml as a function of type
:int list -> int
What function results by recursion if a = 1 and b(n,s) = n*s?
- What function results by recursion if a = 0 and b(n,s) = n+s?
- What function results by recursion if a = 1 and b(n,s) = 2*n?
- Give a recursive function in OCaml that to k returns the sum of the first k odd natural numbers.
- Give a recursive function in Ocaml that to k returns the sum of the first k cubes.
f(0) = 0, f(1) = 1, f(2) = 9