Skip to content

Instantly share code, notes, and snippets.

@kjellski
Created March 26, 2015 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjellski/cc81bafdc5558ff65577 to your computer and use it in GitHub Desktop.
Save kjellski/cc81bafdc5558ff65577 to your computer and use it in GitHub Desktop.
at
//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