I need to write a function that takes a list of strings and finds the largest string in the list. The catch is it needs to iterate through the list using List.foldl and cannot use recursive calls except for those in the library function of List,foldl.
I wrote
fun longest_string1(xs)=
case xs of
[] => ""
| x::xs' => List.foldl((fn (s,x) => if String.size s > String.size x then s else x) "" x,)
with my interpretation being as follows:
-take in xs, if xs is empty return an empty string
-otherwise for the first item of xs call List.foldl
-List.foldl passes in an anonymous function that checks the length of s, which should represent the accumulator against the head item of the list.
-Set the initial accumulator to be the empty string and the initial compare value to be the head of the initial list passed in by the higher order function
However, it does not type check.
I think my issue is in the understanding of the List.foldl function itself and how exactly it reads in its parameters. Can someone please provide some clarification?