Created
March 28, 2017 17:49
-
-
Save ccorcos/caf42ba18a47e0b0f9545e984b38195d to your computer and use it in GitHub Desktop.
This file contains 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
type result 'a = {mutable list: list 'a}; | |
let firstN (n: int) (l: list 'a) :list 'a => { | |
let result: result 'a = {list: []}; | |
let start = 0; | |
let stop = min (n - 1) (List.length l - 1); | |
for i in start to stop { | |
result.list = List.append result.list [List.nth l i] | |
}; | |
result.list | |
}; | |
firstN 2 [1, 2, 3, 4, 5]; /* => list int: [1, 2] */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment