Skip to content

Instantly share code, notes, and snippets.

@ccorcos

ccorcos/nth.re

Created Mar 28, 2017
Embed
What would you like to do?
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