what is this sml: `fun max xs = foldl int.max (hd xs) (tl xs)` in ocaml and in ruby

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 chars
2 lines

In Ruby, it would be:

main.rb
def max(xs)
  xs.reduce { |max, x| max > x ? max : x }
end
59 chars
4 lines

This code finds the maximum value in a list of integers in both OCaml and Ruby.

related categories

gistlibby LogSnag