Skip to content

Instantly share code, notes, and snippets.

@CaglarGonul
Last active December 15, 2015 09:09
Show Gist options
  • Save CaglarGonul/5236709 to your computer and use it in GitHub Desktop.
Save CaglarGonul/5236709 to your computer and use it in GitHub Desktop.
A simple selection algorithm for finding the maximum integer option in an integer list is given below :
fun max_case (xs) =
case xs of
[] => NONE
| x::xs' => let fun non_empty_max (ys) =
case ys of
[] => x
| y::ys' => let val tl_ans = non_empty_max (ys')
in
if y > tl_ans
then y
else tl_ans
end
in SOME (non_empty_max (xs'))
end
val test_max_case = max_case ([1,2,3,4,5,6,7,8,9,10])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment