F# is a multi-paradigm .NET language explicitly designed to be an ML suited to the .NET environment. or, F# is a functional programming language that runs on Microsoft's Common Language Runtime and the .NET Framework. F# programming is basically a combination of three Functional Programming as well as Imperative and Object Oriented Programming Concepts. The first paradigm is Functional programming. The second paradigm is widely adopted Object oriented programming. The third paradigm supported by F# is Language oriented programming.
Data Types In F#
Here, we will describes the types that are used in F#.
Primitive Types in F# ( Fundamental Data Types of F#)
Some types are considered primitive types, such as the Boolean type bool and integral and floating point types of various sizes, which include types for bytes and characters. these are also called Fundamental Data Types of F#.
The below table defines the Primitive Types of F#.
| Data Type Name | F# type | Example | Size |
| Short | int16 | 10s | 2 byte with a sign bit |
| Unsigned Short | uint16 | 80us | 2 byte with no sign bit |
| Unsigned int | uint32 | 456u | 4 byte with no sign bit |
| Unsigned long | uint64 | 9999999ul | 8 byte with no sign bit |
| Single | float32 or single | 2.0f, 2.02f, 2.02e20 | 4 byte with a sign bit |
| Native int | nativeint | 456n | Size is platform specific |
| Unsigned Native int | unativeint | 456un | Size is Platform specific |
| Decimal | decimal | 456m | Maps to System.Decimal |
| Big number | bignum | 456I | Maps to Microsoft.FSahrp.Math.BigInt |
Other Data Types of F#
These data type are the built in data types in the language, which includes tuples, lists, arrays, sequences, records, and discriminated unions.
Tuples
A tuple is defined as a comma separated
collection of values. For example, (8, "hi")
is a 2-tuple with the type (int * string).
Tuples are extremely useful for creating ad hoc data structures which group
together related values. or, A tuple is a grouping of unnamed but ordered
values, possibly of different types.
For example
Tuple of two integers.
(5, 6)
Names of Tuple Types
When you write out the name of a type that is a tuple, you use the * symbol to separate elements. For a tuple that consists of two int,
such as (5,6) the type would be written as follows.
int *int
Triple of strings
("Mical","Manoj","Gray")
Names of Tuple Types
String* String*string*
Tuple that has mixed types.
( "one", "1", "2.0" )
Names of Tuple Types
String*int*float
Records
A record is similar to a tuple, except that it contains named fields. F# record types are a simple named type. You can create one or more variables in a record. When you need to access the record you can access the complete record or one of its members individually.
The syntax to create a record is:
type recordName = { [ fieldName : dataType ] + }
Example:
type website ={ Title : string; Url : string; view : int }
Lists
List data types are ordered, immutable series of elements all of the same type. A F# list is a typical linked list type. It can be either a empty list or a cell containing a value or a reference to the tail, which is itself a list. Lists in F# is an immutable and ordered series of elements.




Join the conversation! Your thoughts help the community grow.