Skip to content

Instantly share code, notes, and snippets.

@Kraks
Created October 9, 2013 11:26
Show Gist options
  • Select an option

  • Save Kraks/6899767 to your computer and use it in GitHub Desktop.

Select an option

Save Kraks/6899767 to your computer and use it in GitHub Desktop.
Recursive Max and Min
fun compare(xs: int list, f: int * int -> int) =
if length xs = 2
then f(hd xs, hd(tl xs))
else f(hd xs, compare(tl xs, f))
fun max(x: int, y: int) =
if x < y
then y
else x
fun min(x: int, y: int) =
if x < y
then x
else y
compare([3, 4, 5, 1], max)
compare([3, 4, 5, 1], min)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment