an introduction to f part 2 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Let the |> fun begin PowerPoint Presentation
Download Presentation
Let the |> fun begin

Loading in 2 Seconds...

play fullscreen
1 / 21

Let the |> fun begin - PowerPoint PPT Presentation


  • 80 Views
  • Uploaded on

An introduction to F# (part 2). Let the |> fun begin. Bogdan Brinzarea-Iamandi Banca Romaneasca. 25 February 2010. Agenda. Asynchronous and parallel programming. Why should these matter to me?. Why should these matter to me?. Working with threads is difficult

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Let the |> fun begin' - moriah


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
an introduction to f part 2
An introduction to F# (part 2)

Let the |> fun begin

Bogdan Brinzarea-Iamandi

BancaRomaneasca

25 February 2010

why should these matter to me1
Why should these matter to me?
  • Working with threads is difficult
  • Synchronizing and sharing state are difficult
  • Introducing bugs is easy
  • The code is complicated
parallel and reactive language
Parallel and reactive language
  • Multiple active evaluations (threads computing results)
  • Multiple pending reactions (callbacks and agents waiting for events and messages)
background worker pattern
Background worker pattern
  • Not useful for asynchronous operations
  • Imperative programming
  • Sharing mutable data between threads
  • Cancellations
  • Raising events in the right thread
immutability
Immutability
  • Optimization opportunities
  • Easily transferable between threads
  • Reliability
async advantages
Async advantages
  • Ease of change
  • Cancellation checking
  • Simple resource management
  • Exception propagation
async
async {…}
  • Creates async objects
  • These tasks can be run
    • In the current thread
    • In a background thread
    • In parallel using fork/join mechanism
    • As continuations
async parallel
Async.Parallel
  • Takes async objects and creates async tasks
  • Uses QueueUserWorkItem
  • Fork/join pattern
  • Does not report progress

seq<Async<'T>> -> Async<'T Array>

async runsynchronously
Async.RunSynchronously
  • Runs synchronous computation
  • Waits for the result
  • Batch processing jobs
  • Matrix multiplication
async startwithcontinuations
Async.StartWithContinuations
  • Starts and ends in the same thread
  • Useful for UI updating
  • Continuations for:
    • Complete
    • Exception
    • Cancellation
async1
! = async
  • let! for async method calls
  • The thread is suspended until the result in available
  • The rest of the code runs as a continuation
  • use! resource disposing equivalent of let!
parallel programming
Parallel programming
  • Leverage parallel hardware capabilities
  • Data parallel programming with PLinq
    • Easy to implement
    • Abstracts away complexity
    • Transparent partition and merge operations
    • Works on seq<a> and IEnumerable<T>
  • Task parallel programming using the new Task Parallel Library in .NET 4.0
agent model concurrency
Agent model concurrency
  • Erlang message passing style
  • “An actor is a computational entity that, in response to a message it receives, can concurrently:
      • send a finite number of messages to other actors;
      • create a finite number of new actors;
      • designate the behavior to be used for the next message it receives.”
agent model concurrency1
Agent model concurrency
  • Asynchronous message passing
  • Can have even 1000 agents
  • Agents are lightweight
  • Based on async programming
  • State isolation between agents
  • No concurrency and data races
functional approach
Functional approach
  • FsUnit based on NUnit
  • FsCheck inspired from Haskell’s QuickCheck
  • FsTest based on xUnit.net
  • NaturalSpec based on NUnit
  • FsSpec readable DSL
resources
Resources
  • Expert F# by Don Syme
  • Programming F# by Chris Smith
  • CTO Corner - http://ctocorner.com/fsharp/book/
  • HubFS

http://cs.hubfs.net/

  • Matthew Podwysocki

http://weblogs.asp.net/podwysocki/

  • Don Syme

http://blogs.msdn.com/dsyme

  • Chris Smith

http://blogs.msdn.com/chrsmith/