Introduction to FSharp

31
www.dotnet.lv

Transcript of Introduction to FSharp

Page 1: Introduction to FSharp

www.dotnet.lv

Page 2: Introduction to FSharp

Valdis IljuconoksTechnical Fellow, Software ArchitectMicrosoft MVP

Geta AS, Viiar [email protected]://dotnet.lv/blogs/vi@tech_fellow

Page 3: Introduction to FSharp

F#

Page 4: Introduction to FSharp

what is it?

Page 5: Introduction to FSharp

x = x + 1

Page 6: Introduction to FSharp

First official functional programming language

on .Net

Page 7: Introduction to FSharp

why?

Page 8: Introduction to FSharp

do more with lesssee where C# and VB.NET are headed

learn new language every year

Page 9: Introduction to FSharp

functionalobject-oriented

imperative

Page 10: Introduction to FSharp

Theorem proving ISWIM (1966)

MLCAML

OCAMLF#

Page 11: Introduction to FSharp

‘let’ binding

Page 12: Introduction to FSharp

let a = 2

Page 13: Introduction to FSharp

let a = 2 int a = 2≠// F# // C#

Page 14: Introduction to FSharp

let a = 2 static int a(){ return 2;}

// F# // C#

Page 15: Introduction to FSharp

Immutable by default

let a = 2let a = 3

error: FS0037 Duplicate definition of value ‘a’

Page 16: Introduction to FSharp

StrongStatic

WeakDynamic

Page 17: Introduction to FSharp

functions

Page 18: Introduction to FSharp

let sqr x = x * x

> val sqr : int -> int

sqr 5

> val it: int = 25

parameter

signature

result

data type

Page 19: Introduction to FSharp

demo

sum of sqr of t

Page 20: Introduction to FSharp

high order functions

A higher-order function is a function

that takes another function as a parameter,or a function that returns another function as a value,

or a function which does both.

Page 21: Introduction to FSharp

let sqr x : float = x * xlet mply a b : float = a * b

let mplyPI a = mply a 3.14159

let cylinderVolume radius length = mplyPI length * sqr radius

Page 22: Introduction to FSharp

demo

function pipelining (|>)

Page 23: Introduction to FSharp

demo

function composition (>>)

Page 24: Introduction to FSharp

discriminated unions

Page 25: Introduction to FSharp

type NullableInt = | Value of int | Nothing of unit

match x with | Value -> ... | Nothing -> ...

Page 26: Introduction to FSharp

interoperability

Page 27: Introduction to FSharp

demo

.Net interoperability

Page 28: Introduction to FSharp

First official functional programming language

on .Net

Page 29: Introduction to FSharp

?

Page 30: Introduction to FSharp

Valdis IljuconoksTechnical Fellow, Software ArchitectMicrosoft MVP

Geta AS, Viiar [email protected]://dotnet.lv/blogs/vi@tech_fellow

Page 31: Introduction to FSharp

www.dotnet.lv