Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. a should be 1. (i) Write recursive function lastTrue : (int -> bool) -> int -> int such that lastTrue f n is the
2. a should be 1. (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 x f n (ii) Using lastTrue, 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 first True : (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 x f n should be -1. (iv) If lastTrue (fun x -> f x > f (x + 1)) 100 evaluates to -1, what can you say about f? How about if lastTrue f 100 firstTrue f 100 is true? = 2. a should be 1. (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 x f n (ii) Using lastTrue, 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 first True : (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 x f n should be -1. (iv) If lastTrue (fun x -> f x > f (x + 1)) 100 evaluates to -1, what can you say about f? How about if lastTrue f 100 firstTrue f 100 is true? =
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started