Last active
December 15, 2015 09:09
-
-
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 :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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