Created
March 28, 2017 17:55
-
-
Save ccorcos/c3f9ac447e07ba7bf00a4d8082ae3618 to your computer and use it in GitHub Desktop.
This file contains 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
let rec nth l n => | |
switch l { | |
| [] => None | |
| [h, ...t] => n === 0 ? Some h : nth t (n - 1) | |
}; | |
let x = nth [0, 1, 2, 3] 999; /* option int: None */ | |
switch x { | |
| Some i => print_int i | |
| None => print_string "not found!" | |
}; | |
let y = nth [0, 1, 2, 3] 1; /* option int: Some 1 */ | |
switch y { | |
| Some i => print_int i | |
| None => print_string "not found!" | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment