Skip to content

Instantly share code, notes, and snippets.

@c-cube
Forked from kindlychung/1.ml
Last active August 29, 2015 14:15
Show Gist options
  • Save c-cube/41941b7a7bced87de65a to your computer and use it in GitHub Desktop.
Save c-cube/41941b7a7bced87de65a to your computer and use it in GitHub Desktop.
let rec take n l =
match n, l with
| 0, [] -> []
| _, [] -> raise (Invalid_argument "plop")
| _, h::t when n < 0 -> raise (Invalid_argument "drop")
| 0, _::_ -> []
| _, h::t -> h :: take (n - 1) t;;
take 2 [1; 2; 3; 4];;
take 2 [];;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment