Created
March 26, 2015 13:34
-
-
Save kjellski/cc81bafdc5558ff65577 to your computer and use it in GitHub Desktop.
at
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 at (pos: int) (l: 'a list) : 'a Option = | |
// if pos - 1 > l.Length - 1 then | |
// None | |
// else if pos = 1 then | |
// Some(l.Head) | |
// else | |
// at (pos - 1) l.Tail | |
let rec at pos = function | |
| [] -> None | |
| x::xs -> if pos = 1 then Some x else at (pos - 1) xs | |
Some "c" = (at 3 [ "a" ; "b"; "c"; "d"; "e" ]);; | |
Some "e" = at 5 [ "a" ; "b"; "c"; "d"; "e" ];; | |
None = at 3 [ "a" ];; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment