Skip to content

Instantly share code, notes, and snippets.

@thednaz
Created June 8, 2012 18:08
Show Gist options
  • Save thednaz/2897337 to your computer and use it in GitHub Desktop.
Save thednaz/2897337 to your computer and use it in GitHub Desktop.
F# list reverse
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