I spotted a typo in exercise 16 : the function divide that you have given has labeled arguments (type dividend:int -> divisor:int -> int) but you use it without labels (int->int->int) : let modulo ~dividend ~divisor = dividend - (divisor * divide dividend divisor)
You should instead write : let modulo ~dividend ~divisor = dividend - (divisor * divide ~dividend ~divisor)
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;;
Thank you for sharing :)
I spotted a typo in exercise 16 : the function
divide
that you have given has labeled arguments (typedividend:int -> divisor:int -> int
) but you use it without labels (int->int->int
) :let modulo ~dividend ~divisor = dividend - (divisor * divide dividend divisor)
You should instead write :
let modulo ~dividend ~divisor = dividend - (divisor * divide ~dividend ~divisor)
wew! guess so! thank you! will update. sorry about that!
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!!