gistlib
Here's a way to find the max value of a list of integers in OCaml using recursion:
let rec max_of_list lst = match lst with | [] -> failwith "Empty list" | [x] -> x | hd::tl -> max hd (max_of_list tl) let result = max_of_list [2; 4] 167 chars8 lines
let rec max_of_list lst = match lst with | [] -> failwith "Empty list" | [x] -> x | hd::tl -> max hd (max_of_list tl) let result = max_of_list [2; 4]
You can run this code in an OCaml environment to find the max value of the list [2; 4], which should give you 4.
[2; 4]
4
gistlibby LogSnag