This Ocaml code traverses a list and outputs the last element.
I dont understand the second condition where we output Some x
let rec last = function | [] -> None | x::[] -> Some x| _ :: t -> last t ;;
- So if the list is empty we return null.
- If x is the last element we return
Some x
(* what is Some x in this context? *) - If x is not the last element we go further in the list.