Download presentation
Presentation is loading. Please wait.
Published byVictor Williston Modified over 9 years ago
1
F# and its 11 features Guanru Li 2011 ACM class
2
F# is …... a programming language.
3
F# is …... a functional programming language
4
F# is …... a functional programming language for.NET
5
F# is …... a functional and object oriented programming language for.NET
6
F# is …... a functional, object oriented and imperative programming language for.NET
7
F# is …... a multi-paradigm programming language for.NET
8
F# is …...a multi-paradigm programming language for.NET, ideally suited for technical, symbolic and algorithmic applications
9
F#
10
Why named F#? ► C# ► Functional programming
11
Hello F#, Hello n factorial printfn "Hello F#!“ let rec factorial n = match n with | 0 -> 1 | _ -> n * factorial(n - 1)
12
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
13
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
14
Feature 3 of 11 ► Collection types for immutable data ► Usage: ??
15
Feature 4 of 11 ► Pattern matching (x is a list) let length x = match x with | [] -> “0” | [ _ ] -> “1” | [ _; _ ] -> “2” | _ -> “Too Long!”
16
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
17
Feature 6 of 11 ► Interactive programming
18
Feature 7 of 11 ► Lazy computations & lazy evaluation let x = 10 let result = lazy (x + 10) do something printfn "%d" (result.Force())
19
Feature 8 of 11 ► Object oriented ► Class & inherit ► Single inheritance
20
Feature 9 of 11 ► Imperative programming ► Like C, C++, Java
21
Feature 10 of 11 ► Generics and type inference let makeList a b = [a; b] makeList 1 2 let function1 a = a + 1
22
Feature 11 of 11 ► Asynchronous workflows ► ??
24
Reference ► http://en.wikipedia.org/wiki/F_Sharp_(progr amming_language) ---- wikipedia F sharp http://en.wikipedia.org/wiki/F_Sharp_(progr amming_language) http://en.wikipedia.org/wiki/F_Sharp_(progr amming_language) ► http://msdn.microsoft.com/zh-cn/library/ dd233181 ---- MSDN F# reference http://msdn.microsoft.com/zh-cn/library/ dd233181 http://msdn.microsoft.com/zh-cn/library/ dd233181 ► http://developer.51cto.com/art/201004/192 870.htm ---- 51CTO.com F# new features http://developer.51cto.com/art/201004/192 870.htm http://developer.51cto.com/art/201004/192 870.htm
25
Q&A
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.