Programming Challenges

Let's solve coding challenges to practice compound datatypes.

Challenge 1: Find the longest string in a string list

Write an OCaml function, longest_string: string list -> string option, to find the longest string in a list of strings.

Examples:

longest_string [] = None
longest_string ["a"; "ABC"; "ab"] = Some "abc"

Hint: You can use OCaml’s String.length function to compute the length of a string.

Press + to interact
(** [longest_string n] is the longest string in the string list [l]. *)
let rec longest_string l = None (* TODO: Replace the hard-coded value with your code here *)

Challenge 2: Concatenate strings

Write an OCaml function, ...