Question: in ocaml: Implement a function sum: (int -> int) -> int -> int, which takes as input a func- tion f:int -> int and a

in ocaml:

in ocaml: Implement a function sum: (int -> int) -> int ->

Implement a function sum: (int -> int) -> int -> int, which takes as input a func- tion f:int -> int and a number n. It computes: f(n) + f(n-1) + ... + f(1) + f(0) To get full credit, implement the function sum using higher-order functions tabulate and fold_left. You can get half the points, if you give a correct implementation of sum which does not use the higher-order functions tabulate and fold_left. Recall : - tabulate: int -> (int -> ') -> 'a list tabulate n f returns a list of length n equal to [f(0), ..., f(n)], created from left to right if n > 0. - fold_left: ('a -> ' -> 'a) -> 'a -> 'd list -> 'a fold_left f init [b1,b2, bn] returns f (... (f (f init b1) b2) ...) bn or init if the list is empty. sti let sum f n =

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the function sum using higherorder functions tabulate and foldleft follow the... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!