Created
July 2, 2014 05:42
-
-
Save v2m/3bb2cf5b238d5480946e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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