And here's an implementation of exercise 24 with refs:
letmin_and_maxlst=(* We get the first element as the base for min and max
We are assured that the list is not empty, but else it would throw an exception *)letmin=ref(List.hd_exnlst)inletmax=ref(List.hd_exnlst)inList.iter~f:(funelem->ifelem<!minthenmin:=elem;ifelem>!maxthenmax:=elem)lst;!min,!max;;
I mean, it works just fine, but it is less ambiguous. For example:
would give the wrong result, whereas:
would give the correct one.
And here's an implementation of exercise 24 with refs:
nice, thank you very much!!