introduction to fsharp

Post on 12-Jun-2015

293 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

www.dotnet.lv

Valdis IljuconoksTechnical Fellow, Software ArchitectMicrosoft MVP

Geta AS, Viiar Consultingvaldis.iljuconoks@dotnet.lvhttp://dotnet.lv/blogs/vi@tech_fellow

F#

what is it?

x = x + 1

First official functional programming language

on .Net

why?

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

learn new language every year

functionalobject-oriented

imperative

Theorem proving ISWIM (1966)

MLCAML

OCAMLF#

‘let’ binding

let a = 2

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

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

// F# // C#

Immutable by default

let a = 2let a = 3

error: FS0037 Duplicate definition of value ‘a’

StrongStatic

WeakDynamic

functions

let sqr x = x * x

> val sqr : int -> int

sqr 5

> val it: int = 25

parameter

signature

result

data type

demo

sum of sqr of t

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.

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

demo

function pipelining (|>)

demo

function composition (>>)

discriminated unions

type NullableInt = | Value of int | Nothing of unit

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

interoperability

demo

.Net interoperability

First official functional programming language

on .Net

?

Valdis IljuconoksTechnical Fellow, Software ArchitectMicrosoft MVP

Geta AS, Viiar Consultingvaldis.iljuconoks@dotnet.lvhttp://dotnet.lv/blogs/vi@tech_fellow

www.dotnet.lv

top related