Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago