Created
October 9, 2013 11:26
-
-
Save Kraks/6899767 to your computer and use it in GitHub Desktop.
Recursive Max and Min
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 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