Jane Street OCaml Challenge: Mutable References

OCaml allows you to create a single mutable value using the ref keyword. This is useful for keeping track of changing state.

Example

let x = ref 0 let () = x := !x + 1

Use !x to read the value, and x := new_value to update it.

Your Turn: min_and_max

Write a function min_and_max that returns a tuple (min, max) of a non-empty list of positive integers.

let min_and_max lst = failwith "For you to implement"

Tests

let%test "Testing min_and_max..." = [%compare.equal: int*int] (min_and_max [5;9;2;4;3]) (2,9) let%test "Testing min_and_max..." = [%compare.equal: int*int] (min_and_max [11;15;7;34]) (7,34)