Created
June 8, 2012 18:08
-
-
Save thednaz/2897337 to your computer and use it in GitHub Desktop.
F# list reverse
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 reverse list = | |
match list with | |
|[] -> [] | |
|[x] -> [x] | |
| head::tail -> reverse tail @ [head] | |
let rec rev list acc= | |
match list with | |
| [] -> acc | |
| [x] -> x::acc | |
| head::tail -> rev tail (head::acc) | |
let list = [1..10000] | |
// go to fsi | |
#time;; | |
for i in 0..10 do reverse list |> ignore;; | |
for i in 0..10 do (rev list []) |> ignore;; | |
rev should be much faster |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment