Skip to content

Instantly share code, notes, and snippets.

@v2m
Created July 2, 2014 05:42
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 v2m/3bb2cf5b238d5480946e to your computer and use it in GitHub Desktop.
Save v2m/3bb2cf5b238d5480946e to your computer and use it in GitHub Desktop.
let rec takeFreshConsTail cons n l =
match l with
| [] ->
if n <> 0 then failwith "insufficient length"
setFreshConsTail cons []
| x::xs ->
if n > 0 then
let cons2 = freshConsNoTail x
setFreshConsTail cons cons2
takeFreshConsTail cons2 (n - 1) xs
else
setFreshConsTail cons []
let take n l =
if n < 0 then failwith "negative count"
if n = 0 then []
else
match l with
| [] -> failwith "insufficient length"
| [x] -> if n = 1 then l else failwith "insufficient length"
| x::xs ->
let cons = freshConsNoTail x
takeFreshConsTail cons (n - 1) xs
cons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment