The best way to start with F# is to launch the interactive session and enter some of the idioms to get a feeling how F# looks like.
~> fsi Microsoft (R) F# 2.0 Interactive build 18.104.22.168 Copyright (c) Microsoft Corporation. All Rights Reserved. For help type #help;; >
To assign values to variables you need the ‘let’ keyword; variables in F# are similar to variables in mathematics, you may assign any value you like (therefore the term ‘variable’), but once assigned you can no longer change its value.
> let a = 0;; val a : int = 0
However, you may be surprised when trying out the following in your interactive session:
> let b = 1;; val b : int = 1 > let b = 2;; val b : int = 2 > b;; (* asking the interactive for the value of b *) val it : int = 2 >
It looks like you actually can change the value of variables, however, this is not true, every new line in the interactive session creates a new scope. Inside the new scope you may define again a variable with the same name as already defined in the previous scope.
Now, enter two definitions of the same variable name by entereing the second line using Shift-Return instead of Return.
> let c = 1 - let c = 2;; let c = 2;; ----^ ~/stdin(19,5): error FS0037: Duplicate definition of value 'c'