F# Introduction to Types


Example

Types can represents various kind of things. It can be a single data, a set of data or a function.

In F#, we can group the types into two categories.:

  • F# types:

     // Functions
     let a = fun c -> c
    
     // Tuples
     let b = (0, "Foo")
    
     // Unit type
     let c = ignore
     
     // Records
     type r = { Name : string; Age : int }
     let d = { Name = "Foo"; Age = 10 }
     
     // Discriminated Unions
     type du = | Foo | Bar
     let e = Bar
     
     // List and seq
     let f = [ 0..10 ]
     let g = seq { 0..10 }
    
     // Aliases
     type MyAlias = string
    
  • .NET types

    • Built-in type (int, bool, string,...)
    • Classes, Structs & Interfaces
    • Delegates
    • Arrays