Feb 15, 2008

I tried F# programming.

F# code for Fibonacci number.

let fib n =
let rec fib_iter n a b =
match n with
| 0 -> a
| _ -> fib_iter (n - 1) b (a + b) in
fib_iter n 0 1;;

printfn "%d" (fib 10);;


F# code for a maximum value.

let lst = [3;1;4;1;5;9;2];;

let rec fmax l x =
match l with
| [] -> x
| lh::lt ->
fmax lt
(if x > lh then x
else lh);;

printfn "%d" (fmax lst 0);;


I feel that the expression of F# is more powerful than Scheme.

No comments: