In the previous parts of this webcast series we've developed an F# script that downloads RSS feeds
asynchronously and in parallel and searches them for the specified keywords. We followed the usual F#
development style, so after introducing the basic functional
concepts, we wrote the code in the simples possible style
and demonstrated how to use
System.Net namespaces. Then we
refactored the existing code, to run asynchronously and process
the results potentially in parallel, which was very easy thanks to F# asynchronous workflows.
In this part of the series, we'll make the next evolutionary step of our sample application. We'll turn the code that originally used F# tuples and lists into code that uses standard .NET objects and we'll also see how to declare a class in F#. This simple modification will turn the script into an F# library that is almost indistinguishable from a library developed in C#. We'll also look how you can use the library from C# web application to show the interop between C# and F# in practice. We'll start with the code from the previous part, so if you missed that, you may want to check it out or download the source code.
In this webcast, we'll look at improving the code for downloading and
processing RSS feeds that I presented in the second part
(if you didn't see earlier parts, the first one was an introduction to
basic functional ideas). The previous part demonstrated how to use .NET libraries
and we implemented a simple
downloadUrl function for obtaining content
of from the web and we've also seen how to load the data into an XML document object
and how to filter items. In this part, we'll modify the code to run asynchronously and
potentially in parallel. To use some of the functionality, you'll need to get
FSharp.PowerPack.dll, which is available with the VS 2008 installation or
as a separated download for VS 2010 .
Now that we have the first version of the code, we can start refactoring it. I'm using the term in a slightly vague meaning - we're of course going to change the behavior of the code. We'll wrap it into F# asynchronous workflow to run without blocking threads and we'll also run multiple downloads in parallel. However, this can still be viewed as refactoring in some sense, because we're not changing the core behavior of the code. As you can see from the webcast, these kinds of refactorings are also very nicely supported by F# syntax...
About a week ago I posted the first part of my F# webcast series. It focused on explainining the basic ideas behind functional programming such as immutability, recursion and passing functions as arguments to other functions (or methods in C#). In the first part, we've seen some C# code to demonstrate the ideas and also a bit of F#, mainly to show the basic language features.
The second part is going to be exclusively about F#. It'll demonstrate how we can start writing
a demo application that grabs data from RSS feeds and processes them. You'll learn how to access
.NET libraries from F# (in particular, we'll use
We'll develop the code iteratively, which means that we'll start by simply enumerating the RSS elements using
for loop and printing the results and then we'll refactor the code to use tuples and sequence expressions to turn it into processing code that generates a sequence of feed items. Finally we'll also demonstrate how to use some of the functions from the previous part such as
List.filter in practice.