Last active
February 3, 2017 16:55
-
-
Save thedgbrt/9e76bdfa785d5a26f4ade9037256bde1 to your computer and use it in GitHub Desktop.
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
(* It's code I wrote while solving a problem in a Functional Programming course in December 2016 *) | |
(* Coming from OOP, I love how elegant and readable it is *) | |
fun card_value ( card : card ) = | |
case card of | |
( _, Num i ) => i | |
| ( _, Ace ) => 11 | |
| ( _, _ ) => 10 | |
fun sum_cards ( cs : card list ) = | |
let | |
fun sum ( cs, acc ) = | |
case cs of | |
[] => acc | |
| c :: cs' => sum ( cs', acc + card_value c ) | |
in | |
sum ( cs, 0 ) | |
end | |
val test = sum_cards [(Clubs, Num 2),(Clubs, Num 2)] = 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment