Valdis Iljuconoks Technical Fellow, Software Architect Microsoft MVP Geta AS, Viiar Consulting [email protected] http://dotnet.lv/blogs/vi @ tech_fellow
F#
what is it?
x = x + 1
First official functional programming language on .Net
why?
do more with less see where C# and VB.NET are headed learn new language every year
functional object-oriented imperative
Theorem proving ISWIM (1966) ML CAML OCAML F#
‘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 = 2 let a = 3 error: FS0037 Duplicate definition of value ‘a’
Strong Static Weak Dynamic
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 * x let 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 Iljuconoks Technical Fellow, Software Architect Microsoft MVP Geta AS, Viiar Consulting [email protected] http://dotnet.lv/blogs/vi @ tech_fellow