Skip to content

Instantly share code, notes, and snippets.

@kindlychung
Last active August 29, 2015 14:15
Show Gist options
  • Save kindlychung/aa556930b68abf2538cf to your computer and use it in GitHub Desktop.
Save kindlychung/aa556930b68abf2538cf to your computer and use it in GitHub Desktop.
let rec take n l =
match l with
[] ->
(
match n with
0 -> []
| _ -> raise (Invalid_argument "take")
)
| h::t ->
if n < 0 then raise (Invalid_argument "take")
else if n = 0 then []
else 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