Skip to content

Latest commit

 

History

History
19 lines (14 loc) · 1.2 KB

w4_2.1_first_class_functions.md

File metadata and controls

19 lines (14 loc) · 1.2 KB

USING FIRST CLASS FUNCTIONS (20 points possible)

  1. Write a function compose : ('a -> 'a) list -> ('a -> 'a) that takes as argument a list l of functions, and that returns the function that is the composition of the functions in l. For instance, compose [f;g;h] x = f (g (h x)). Or with concrete functions, compose [(fun x -> x+1);(fun x -> 3*x);(fun x -> x-1)] 2 = 4.

  2. Write a function fixedpoint : (float -> float) -> float -> float -> float that takes a function f of type float -> float and two floating-point arguments start and delta. The function fixedpoint applies repetitively f to the result of its previous application, starting from start, until it reaches a value y where the difference between y and (f y) is smaller than delta. In that case it returns the value of y. For instance, fixedpoint cos 0. 0.001 yields approximately 0.739 (ref).

THE GIVEN PRELUDE

type int_ff = int -> int

YOUR OCAML ENVIRONMENT

let rec compose = function _ ->
  "Replace this string with your implementation." ;;

let rec fixedpoint f start delta =
  "Replace this string with your implementation." ;;