If you’re reading this I’m assuming that you have a background in software development (.NET in particular) so I won’t do more than show the keyword to .NET type mappings and highlight a few notable items.
As a .NET language F# supports the same primitives as the traditional .NET languages. Also like other .NET languages, F# supports suffixes on most numeric types to remove ambiguity. Using suffixes in your code can help the type inference engine resolve types, reducing the need for explicit type annotations.
|F# Keyword||.NET Type||Suffix|
|int (or int32)||System.Int32||l (optional)|
|uint (or uint32)||System.UInt32||u|
|decimal||System.Decimal||m (or M)|
|float (or double)||System.Double|
|float32 (or single)||System.Single||f (or F)|
Although it is not a primitive type, F# also exposes System.BigInteger via the bigint keyword for computations with integers larger than 64-bits.
You should already be familiar with most of the types listed above but there’s one type that’s specific to F#. The unit type, denoted by (), represents the absence of an actual value but should not be confused with null or void. The unit value is generally used where a value would be required by the language syntax but not by the program logic such as the return value for functions that are invoked for their side-effect(s) rather than their result.
One important way that F# differs from other .NET languages is that it does not allow implicit type conversions because of bugs that can arise due to type conversion errors. Instead we can explicitly convert values using the built-in conversion functions.
(float 1) + 2.0 |> printfn "%A"
In the example we convert the int value to float by passing it to the float function and add it to the existing float value.