F#语言对异步程序设计的支持
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

F#语言对异步程序设计的支持

  • 3,316 views
Uploaded on

如今的Web应用、 Silverlight以及各种分布式系统让异步解决方案有了更进一步的需求。F#是微软.NET平台上的函数式编程语言,并添加了不少让并行及异步编程变得有趣且轻松的特性。本次演讲将讨论F#的核心概念,并探讨F#中的不可变性、函数式设计、异步工作流、代理等特性是如何应对真实应用中的异步挑战的。

如今的Web应用、 Silverlight以及各种分布式系统让异步解决方案有了更进一步的需求。F#是微软.NET平台上的函数式编程语言,并添加了不少让并行及异步编程变得有趣且轻松的特性。本次演讲将讨论F#的核心概念,并探讨F#中的不可变性、函数式设计、异步工作流、代理等特性是如何应对真实应用中的异步挑战的。

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,316
On Slideshare
2,373
From Embeds
943
Number of Embeds
15

Actions

Shares
Downloads
83
Comments
0
Likes
1

Embeds 943

http://blog.zhaojie.me 908
http://nbazaar.org 17
http://static.slidesharecdn.com 4
http://www.zhuaxia.com 3
http://www.soso.io 1
http://chebulic14.knotyapi.com 1
http://translate.googleusercontent.com 1
http://cache.baidu.com 1
file:// 1
http://nbazaar-int.org 1
http://reader.youdao.com 1
res://d:%5cprogra~1%5cthewor~1%5cextens~1%5cextrss~1%5cextrss~1.dll 1
http://zhuaxia.com 1
http://m351.mail.qq.com 1
http://dungier13.rssing.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Async Programming in F# Zhao Jie - SNDA - June 2010
  • 2. About Me • / / Jeffrey Zhao / • Programmer • Blogger - http://blog.zhaojie.me/ • Twitterer: @jeffz_cn • F#, Scala, JavaScript, Python, .NET, mono... • Java (as the language) hater
  • 3. What’s F# • Languages by Don Syme, MS Research • Strongly Statically Typed Language • Functional Language with OO Ability • General Purpose Language
  • 4. Async programming is complex ...
  • 5. ...and will only get more complex in the near future
  • 6. Four Big Concurrency Challenges • Shared State • Code Locality • I/O Parallelism • Scaling Up
  • 7. Shared State • Difficult to maintain and test • Very difficult to parallelize • Locking is fundamentally error prone ‣ Must guess where parallelism is needed ‣ All consumers need to participate
  • 8. Demo: Immutability
  • 9. Immutability in F# • Immutable Union • Immutable Tuple • Immutable Record • Immutable List • Immutable Set • Immutable Map • Immutable Objects • Immutable ...
  • 10. Code Locality • Used to expressing algorithms linearly • Async requires logical division of algorithms • Very difficult to ‣ Combine multiple asynchronous operations ‣ Deal with exceptions and cancellation
  • 11. Asynchronous Workflow async  {  ...  }
  • 12. React async  {        let!  res  =  <async  work>        ...  } an HTTP Response an UI Event a Timer Callback a Query Response a Web Servcie Response a Disk I/O Completion an Agent Message
  • 13. async  {        let!  img  =  AsyncRead  "http://..."        printfn  "loaded!"        do!  AsyncWrite  img  @"c:..."        printfn  "saved!"  } = async.Delay(fun  -­‐>        async.Bind(AsyncRead  "http://...",  (fun  img  -­‐>                printfn  "loaded!"                async.Bind(AsyncWrite  img  @"c:...",  (fun  ()  -­‐>                        printfn  "saved!"                        async.Return())))))
  • 14. Demo: Code Locality
  • 15. I/O Parallelism • Software is often I/O-bound ‣ Leveraging web services ‣ Working with data on disk • Network and disk speeds increasing slower • I/O resources are inherently parallel ‣ Huge opportunity for performance
  • 16. Demo: I/O Parallelism
  • 17. Scaling to Multi-Machine • To scale up, must to go beyond a single machine • Multi-machine resources becoming common ‣ Roll-you-own clusters with cheap hardware ‣ On-demand cloud compute with Azure • But ‣ Shared memory doesn’t scale
  • 18. ... the principle we go by is, don't expect to see a particular concurrency model put into C# because there're many different concurrency model ... it's more about finding things are common to to all kinds of concurrency ... - Anders Hejlsberg
  • 19. Demo: Agents
  • 20. Concurrency Challenges • Shared State - Immutability • Code Locality - async { ... } • I/O Parallelism - async { ... } • Scaling to Multi-Machine - Agents
  • 21. F# • Modern, simple, powerful and productive • Ready for production use with VS 2010 • Simplified parallel and async programming for today and tomorrow • Support .NET 4.0 / 3.5 and mono • Open Source *
  • 22. F# Resources http://fsharp.net Programming F# Expert F# 2.0 Real World FP
  • 23. Q &A
  • 24. Thanks!