gistlib
In OCaml, the equivalent code to the SML code you provided would be:
let max xs = List.fold_left max (List.hd xs) (List.tl xs);; 60 chars2 lines
let max xs = List.fold_left max (List.hd xs) (List.tl xs);;
In Ruby, it would be:
main.rbdef max(xs) xs.reduce { |max, x| max > x ? max : x } end 59 chars4 lines
def max(xs) xs.reduce { |max, x| max > x ? max : x } end
This code finds the maximum value in a list of integers in both OCaml and Ruby.
gistlibby LogSnag