DEV Community

Discussion on: OCaml Speedrun! 🐫🐪

Collapse
 
christopheriolo profile image
Christophe Riolo

I mean, it works just fine, but it is less ambiguous. For example:

divide divisor dividend

would give the wrong result, whereas:

divide ~divisor ~dividend

would give the correct one.

Collapse
 
christopheriolo profile image
Christophe Riolo

And here's an implementation of exercise 24 with refs:

let min_and_max lst =
    (* 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 *)
    let min = ref (List.hd_exn lst) in
    let max = ref (List.hd_exn lst) in
    List.iter ~f:(fun elem ->
        if elem < !min then min := elem;
        if elem > !max then max := elem
    ) lst;
    !min, !max
;;
Thread Thread
 
swyx profile image
swyx

nice, thank you very much!!