Monday, February 2, 2009

F# – Sequential code

F# can handle sequential code. Expressions evaluated sequentially. Just the last result will be kept, other results will be dismissed to prevent side effects.

#light
let a = (2+3;5+7;4+4)
printfn "a= %d" a
let b = (a+2;a+5)
printfn "b= %d" b
a= 8
b= 13

It can be useful when we are doing complicated computations or initializations and we want to indicate the progress:

printf "Processing"
let c = (printf ".."; 2; printfn ".."; 3)
printfn "c= %d" c
Processing....
c= 3

No comments:

Post a Comment