F# and its 11 features Guanru Li 2011 ACM class
F# is …... a programming language.
F# is …... a functional programming language
F# is …... a functional programming language for.NET
F# is …... a functional and object oriented programming language for.NET
F# is …... a functional, object oriented and imperative programming language for.NET
F# is …... a multi-paradigm programming language for.NET
F# is …...a multi-paradigm programming language for.NET, ideally suited for technical, symbolic and algorithmic applications
F#
Why named F#? ► C# ► Functional programming
Hello F#, Hello n factorial printfn "Hello F#!“ let rec factorial n = match n with | 0 -> 1 | _ -> n * factorial(n - 1)
Feature 1 of 11 ► Functional programming let f (g: int -> int) y = g y let increment x = x + 1 let a = f increment 100 ► Lambda expression let f (g: int -> int) y = g y let a = f (fun x -> x + 1) 100
Feature 2 of 11 ► Compose the functions! let function1 x = x + 1 let function2 x = x * 2 let h = function1 >> function2 let a = h 100
Feature 3 of 11 ► Collection types for immutable data ► Usage: ??
Feature 4 of 11 ► Pattern matching (x is a list) let length x = match x with | [] -> “0” | [ _ ] -> “1” | [ _; _ ] -> “2” | _ -> “Too Long!”
Feature 5 of 11 ► Discriminated unions type Shape = | Circle of float | Square of double let area myShape = match myShape with | Circle r -> 3.14*r*r | Square r -> s*s
Feature 6 of 11 ► Interactive programming
Feature 7 of 11 ► Lazy computations & lazy evaluation let x = 10 let result = lazy (x + 10) do something printfn "%d" (result.Force())
Feature 8 of 11 ► Object oriented ► Class & inherit ► Single inheritance
Feature 9 of 11 ► Imperative programming ► Like C, C++, Java
Feature 10 of 11 ► Generics and type inference let makeList a b = [a; b] makeList 1 2 let function1 a = a + 1
Feature 11 of 11 ► Asynchronous workflows ► ??
Reference ► amming_language) ---- wikipedia F sharp amming_language) amming_language) ► dd MSDN F# reference dd dd ► htm CTO.com F# new features htm htm
Q&A