Kean Walmsley on using F# Asynchronous Workflows to simplify concurrent programming in AutoCAD

On Friday Kean Walmsley posted an excellent article on Using F# Asynchronous Workflows to simplify concurrent programming in AutoCAD.I've quoted some it below.

There are two things I especially like about this post. First, Kean's code is very clean and some of the best F# app-extension scripting I've seen.

Second, Kean took the time to highlight the minor differences between the synchronous and parallel versions of his algorithm. Of the 235 lines, only 13 lines of code and 7 lines of comments changed, and even for those there is a very close correspondence between the versions. Allowing programmers to achieve this correspondence was one of the key design goals of asynchronous workflows.

Here are some snippets from Kean:

As promised, in today's post we take that code and enable it to query the same data in parallel by using Asynchronous Workflows in F#. Asynchronous Workflows are an easy-to-use yet powerful mechanism for enabling concurrent programming in F#.

Firstly, a little background as to why this type of technique is important. ... Barring some disruptive technological development, the future gains in computing performance are to be found in the use of parallel processing, whether via multiple cores, processors or distributed clouds of computing resources. ... Additionally, with an increasing focus on distributed computing and information resources, managing tasks asynchronously becomes more important...

The big problem is that concurrent programming is - for the most-part - extremely difficult to do, and even harder to retro-fit into existing applications...

 Today's post looks at a relatively simple scenario, in the sense that we want to perform a set of discrete tasks in parallel, harnessing those fancy multi-core systems for those of you lucky enough to have them (I'm hoping to get one when I next replace my notebook, sometime in March)...

We are also going to be very careful only to run parallel tasks unrelated to AutoCAD. Any access made into AutoCAD's database, for instance, needs to be performed in series: AutoCAD is not thread-safe when it comes to the vast majority of its programmatically-accessible functionality. So we're going to run a set of asynchronous, parallel tasks to query our various RSS feeds, and combine the results before creating the corresponding geometry in AutoCAD. This all sounds very complex, but the good (actually great) news is that Asynchronous Workflows [do] all the heavy lifting....

In an earlier post I linked to Kean's entries where he had written his first AutoCAD application using F# and has just followed up with A mathematical F# application integrating with AutoCAD via .NET which embeds one of the F# DirectX demos directly into AutoCAD.


Comments (2)

  1. mps says:

    Kean is running into tali recursion questions/ issues:

    What are your thoughts?

  2. Alex Mikunov says:

    Why bother if we already have Haskell for researchers & C# with lambda support (limited yet) for devs?

    After all, it’s not that difficult to add monads/arrows support to C#.

    Or it’s done to attract functional programming fans to .NET? Is it [again] all about money?

Skip to main content