Question: F-Sharp programming. 2. a (i) Write recursive function lastTrue : (int -> bool) -> int -> int such that lastTrue f n is the largest

F-Sharp programming.

F-Sharp programming. 2. a (i) Write recursive function lastTrue : (int ->

2. a (i) Write recursive function lastTrue : (int -> bool) -> int -> int such that lastTrue f n is the largest integer i in the range 0,...,n 1 such that f i is true. If there is no such i, then lastTrue f n should be 1. (ii) Using last True, write a function lastEqual : 'a -> (int -> 'a) -> int -> int when 'a : equality such that lastEqual x f n is the largest i in 0,...,n-1 such that f i is equal to x. If there is no such i, then lastEqual x f n should be -1. (iii) Write recursive function firstTrue : (int -> bool) -> int -> int such that firstTrue f n is the smallest integer i in the range 0,...,n - 1 such that f i is true. If there is no such i, then firstTrue f n should be -1. (iv) If lastTrue (fun x -> fx > f (x + 1)) 100 evaluates to -1, what can you say about f? How about if lastTrue f 100 firstTrue f 100 is true? a -- = 2. a (i) Write recursive function lastTrue : (int -> bool) -> int -> int such that lastTrue f n is the largest integer i in the range 0,...,n 1 such that f i is true. If there is no such i, then lastTrue f n should be 1. (ii) Using last True, write a function lastEqual : 'a -> (int -> 'a) -> int -> int when 'a : equality such that lastEqual x f n is the largest i in 0,...,n-1 such that f i is equal to x. If there is no such i, then lastEqual x f n should be -1. (iii) Write recursive function firstTrue : (int -> bool) -> int -> int such that firstTrue f n is the smallest integer i in the range 0,...,n - 1 such that f i is true. If there is no such i, then firstTrue f n should be -1. (iv) If lastTrue (fun x -> fx > f (x + 1)) 100 evaluates to -1, what can you say about f? How about if lastTrue f 100 firstTrue f 100 is true? a -- =

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!