val one : int

Full name: index.one
val message : string

Full name: index.message
val MultiplyByFive : arg:int -> int

Full name: index.MultiplyByFive
val arg : int
val MultiplyByFive : (int -> int)

Full name: index.MultiplyByFive
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
module String

from Microsoft.FSharp.Core
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
Multiple items
val decimal : value:'T -> decimal (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.decimal

--------------------
type decimal = System.Decimal

Full name: Microsoft.FSharp.Core.decimal

--------------------
type decimal<'Measure> = decimal

Full name: Microsoft.FSharp.Core.decimal<_>
Multiple items
val float : value:'T -> float (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------
type float = System.Double

Full name: Microsoft.FSharp.Core.float

--------------------
type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>
module Array

from Microsoft.FSharp.Collections
type bool = System.Boolean

Full name: Microsoft.FSharp.Core.bool
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
module Seq

from Microsoft.FSharp.Collections
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.map
val filter : predicate:('T -> bool) -> source:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.filter
val iter : action:('T -> unit) -> source:seq<'T> -> unit

Full name: Microsoft.FSharp.Collections.Seq.iter
module Option

from Microsoft.FSharp.Core
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>

The reasons to use F#



Daniel Oliver - @Twitter

F# language is awesome


The F# community is more awesome.

Alt text

Alt text

Alt text

Alt text

F# language is awesome


The F# community is more awesome.


The F# community makes amazing libraries.

Value comes from what a language can do and how convenient to use.

F# is both convenient and functional.

Libraries for:

The Basics of F# in 5 minutes:

Variables

C#

1: 
2: 
var one = 1;
var message = "Hello world";

F#

1: 
2: 
let one = 1;
let message = "Hello world";

Methods

C#

1: 
2: 
3: 
4: 
int MultiplyByFive(int arg)
{
    return arg * 5;
}

F#

1: 
let MultiplyByFive arg = arg * 5

or

1: 
let MultiplyByFive = (*) 5

Classes

C#

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
class Point
{
    public int X { get; private set; }
    public int Y { get; private set; }
    public Point(int x, int y)
    {
        X = x;
        Y = y;
    }
}

F#

1: 
2: 
3: 
4: 
type Point =
  { X: int
    Y: int
  }

Enums

C#

1: 
2: 
3: 
4: 
5: 
6: 
enum Color
{  
    Red,
    Green,
    Blue
};

F#

1: 
2: 
3: 
4: 
type Color =
  | Red
  | Green
  | Blue

Discriminated Unions

FSharp.Data

F#

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
type JsonValue =
  | String of string
  | Number of decimal
  | Float of float
  | Record of (string * JsonValue)[]
  | Array of JsonValue[]
  | Boolean of bool
  | Null

Discriminated Unions cont.

F#

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
let jsonStruct =
  JsonValue.Record 
    [|  ("UserGroup", JsonValue.String "Nash.NET")
        ("Officers", JsonValue.Record
            [| ("Co-President", JsonValue.String "Debbie")
               ("Secretary", JsonValue.String "Garrett")
               ("Vice President", JsonValue.String "Taylor")
               ("Co-President", JsonValue.String "Daniel")
            |]
        )
    |]
  
printfn "%A" jsonStruct
//Record
//  [|("UserGroup", String "Nash.NET");
//    ("Officers", Record
//       [|("Co-President", String "Debbie"); ("Secretary", String "Garrett");
//         ("Vice President", String "Taylor"); ("Co-President", String "Daniel")|])|]

Pipe operator

F#

1: 
2: 
3: 
4: 
5: 
6: 
[1..100]  //Gives 1, 2, 3, 4, 5 ... 98, 99, 100
|> Seq.map(fun num -> num + 1) //Add one to each number
|> Seq.map((*) 2) //Multiple each by 2
|> Seq.filter(fun num -> num % 3 = 0) //Only accept multiples of 3
|> Seq.iter(printfn "%i") //Print out each number
//6 12 18 24 30 36 42 48 54 60 66 72 ...

Immutability

F#

1: 
2: 
3: 
4: 
let millisecondTimeout = 500 //canNOT be changed

let mutable secondTimeout = 500 //can be changed
secondTimeout <- 200 //Set new value

Immutability is a feature

F#

1: 
2: 
3: 
4: 
5: 
let point1 = { X = 50; Y = 42 } //canNOT be changed

let result = IAmMethod point1 
//I am guaranteed that IAmMethod did not change point1. 
//No "side-effects"

Yeah, this is a small example. But on a big system, it adds comfort when passing an important object into an unknown function.

Null values

C#

1: 
string helloWorld = null;

F#

1: 
No null values

Options

F#

Built into F# is a discriminated union to represent Null. So every usage of Null, becomes a deliberate choice.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
type Option<'a> = //Generic
  | Some of 'a  //Actual Value
  | None       //No Value

let message1 = Some "Super Important Super Secret"
let message2 = None
let printMessage msg = match msg with
                       | Some(text) -> printfn "Message: %s" text
                       | None -> printfn "No Message"
printMessage message1 //Message: Super Important Super Secret
printMessage message2 //No Message

We wouldn't have every column in the database be nullable, why should our code be?

Resources