GIML: Tutorial Six: Hints
The sum function might be defined for lists of reals as follows:
fun sum nil = 0.0
| sum (h::t) = h + sum t;
However we can use reduce instead:
val sum = reduce (op +) 0.0;
Either way we need to map the appropriate function over the list of
countries to obtain a list of populations or GDP's first.
map pop europe;
gives a list of populations which can be summed.
sum (map pop europe);
The major countries might be definied using the function
major which takes a country and returns true if it's population
is at least 1 million.
fun major country = (pop country > 1000000.0);
We can then obtain a list of major countries by filtering the main list.
filter major europe;