2011年8月8日 星期一

F#, Quick sort in F#

F# is a powerful programming language, but there is few lesson to learn on the internet. I try to introduce the F# and write some articles to let me to record what I learn.

There is an example to show the quick qort in F#.

let rec qsort(xs : List<int>) =
  match xs with
  | [] -> []
  | x :: xs ->
      let smaller = qsort (xs |> List.filter(fun e -> e <= x))
      let larger = qsort (xs |> List.filter(fun e -> e >= x))
      smaller @ [x] @ larger
Quiet simple…

沒有留言: