Use foldl
starting with (0,0)
and then at each iteration use the size
function to find out the length of the string and then add 1
to the first or second item of the tuple accordingly.
Edit:
Now that you mention it, an easier way than using foldl
is to use List.partition
. You can use size
to write a function that returns true
iff a string has 6 or fewer characters. You can then use partition with that function, to get a list of strings with 6 or fewer characters and another one with the strings with more than 6 characters.
You can then use length
on both lists to get their length and then return a tuple containing the two lengths.
Edit2:
Here's the code resulting from the comments over multiple lines for readability:
fun shortLong list =
let
val (longs, shorts) = List.partition (fn k => size k > 6) list
in
(length shorts, length longs)
end