Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

let longest_string1 = List.fold_left(fun a b -> if String.length(a) >= String.length(b) then a else b) Write in Ocaml .ml (* #3 *) let longest_string2

let longest_string1 = List.fold_left(fun a b -> if String.length(a) >= String.length(b) then a else b) ""

Write in Ocaml .ml

(* #3 *)

let longest_string2 = List.fold_left(fun a b -> if String.length(a) > String.length(b) then a else b) ""

(*here above are longest_string 1 and longest_string 2, please i need help with question 4 thank you so much

notice longest_string_helper has type (int -> int-> bool) -> string list -> string not ( int * int -> bool ) -> string list -> string

OCAML Language

image text in transcribed

4. Write functions longest_string_helper, longest_string3, and longest_string4 such that: - longest_string3 has the same behavior as longest_string1 and longest_string4 has the same behavior as longest_string2. - longest_string_helper has type (int int bool) string list string (notice the currying). This function will look a lot like longest_string1 and longest_string2 but is more general because it takes a function as an argument. 1 - If longest_string_helper is passed a function that behaves like > (so it returns true exactly when its first argument is strictly greater than its second), then the function returned has the same behavior as longest_string1. - longest_string3 and longest_string4 are bound to the result of calls to longest_string_helper

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions