-
Write a function
compose : ('a -> 'a) list -> ('a -> 'a)
that takes as argument a listl
of functions, and that returns the function that is the composition of the functions inl
. 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
. -
Write a function
fixedpoint : (float -> float) -> float -> float -> float
that takes a functionf
of typefloat -> float
and two floating-point argumentsstart
anddelta
. The functionfixedpoint
applies repetitivelyf
to the result of its previous application, starting fromstart
, until it reaches a valuey
where the difference betweeny
and(f y)
is smaller thandelta
. In that case it returns the value ofy
. For instance,fixedpoint cos 0. 0.001
yields approximately0.739
(ref).
type int_ff = int -> int
let rec compose = function _ ->
"Replace this string with your implementation." ;;
let rec fixedpoint f start delta =
"Replace this string with your implementation." ;;