Question: This is in Ocaml Write a function filter: (a -> bool) -> a list -> a list. The call filter f l should return l

This is in Ocaml

Write a function filter: (a -> bool) -> a list -> a list. The call filter f l should return l with all and only the items for which f returns true; these items should appear in the same order in which they appear in the original list. Some examples:

filter (fun x -> x > 2) [5; 3; 1; 2; 4] = [5; 3; 4]

filter (fun x -> x > 5) [5; 3; 1; 2; 4] = []

Will thumb up thanks!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!