Skip to content

Instantly share code, notes, and snippets.

@ccorcos
Created March 28, 2017 17:54
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 ccorcos/a826b62cd329f0e1f95895816bdf5de3 to your computer and use it in GitHub Desktop.
Save ccorcos/a826b62cd329f0e1f95895816bdf5de3 to your computer and use it in GitHub Desktop.
let nth l n =
if n < 0 then invalid_arg "List.nth" else
let rec nth_aux l n =
match l with
| [] -> failwith "nth"
| a::l -> if n = 0 then a else nth_aux l (n-1)
in nth_aux l n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment