F# Webcast (IV.) - Developing standard .NET libraries

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.Xml and 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.

Get Microsoft Silverlight
Video on Channel 9 | Double click for full-screen | Download WMV video

F# Webcast Series

This webcast series follows the usual F# development process where you start with experimenting and writing an initial version of the solution interactively using the F# interactive tool. In the later phase of the process, we modify the code to make it parallel and asynchronous and finally, we can also encapsulate it into a standard .NET library that's usable from C#. Here is a list of all webcasts in the series:

  • Part I. - Introducing functional concepts
    The first part introduces functional programming principles such as immutability, recursion and functions that take other functions as parameter (higher order functions). This can all be demonstrated in C# 3.0, so we start with C# and then look how the same concepts look in F#. Finally, the first part also shows functions for working with lists in F#.
  • Part II. - Using standard .NET libraries
    The second part demonstrates how we can use standard .NET libraries. It uses classes from System.Net and System.Xml to download content of a web page (RSS feed), load it into XML document and process it to find only posts that contain some specified keyword.
  • Part III. - Downloading web pages asynchronously
    The third part shows how to make the code from the part II. better. It introduces F# asynchronous workflows that can be used for writing code that doesn't block a thread when waiting for the completion of some I/O request. This part also shows how to modify the code to download and process multiple feeds in parallel.
  • Part IV. - Developing standard .NET libraries
    In the fourth part, we look how to encapuslate the functionality written in F# into classes. We'll finally create a project (rather than just use F# scripts) and we'll wrap the code we wrote into a .NET class. We'll also look how to compile the project into DLL and how to use it from a simple C# web application.

Downloads

Published: June 15, 2009 20:09
Tags: Functional Programming in .NET | Asynchronous | Webcast | F# language

Share:


  • RE: F# Webcast (IV.) - Developing standard .NET libraries by Vamper Attila (6/16/2009 9:25:11 AM)

    Dear Tomas !
    Please , if you can, will countinue .. :)

  • RE: F# Webcast (IV.) - Developing standard .NET libraries by Hans Schenker (6/18/2009 3:01:44 PM)

    Tomas, thank's a lot for your very useful F# Sharp Introduction with the RSS Feed Sample!

  • RE: F# Webcast (IV.) - Developing standard .NET libraries by Brian Boyle (7/3/2009 4:46:52 PM)

    Tomas, thank you for the series, it was a very practical and enjoyable introduction.

  • RE: F# Webcast (IV.) - Developing standard .NET libraries by Alexandros Ilatzis (7/25/2009 4:26:57 PM)

    thanks for sharing.
    When using the lib with asp.net the thread that does the work is different from the UI thread. But if you use the lib from the windows forms you have to put the lib in a different thread because it pauses the ui for a certain time.
    What do you think Tomas will you plan to expand this sample or continue those webcasts. They seem usefull.
    thanks

  • RE: F# Webcast (IV.) - Developing standard .NET libraries by Ivo Balbaert (8/14/2009 11:18:48 AM)

    Very nice introduction to F#!
    Thank you very much

  • RE: F# Webcast (IV.) - Developing standard .NET libraries by Ivo Balbaert (8/20/2009 7:40:30 PM)

    When executing the final ASP.NET project: I keep getting the following error:
    System.MissingMethodException was unhandled by user code
    Message=Method not found: 'Microsoft.FSharp.Control.Async`1<System.Net.WebResponse> Microsoft.FSharp.Control.WebRequestExtensions.WebRequest.AsyncGetResponse.1(System.Net.WebRequest)'.
    Source=FSharp.Core
    StackTrace:

    It seems AsyncGetResponse is not there anymore , what should I substitute ?

    Thanks for the brilliant series!
    Ivo

  • RE: F# Webcast (IV.) - Developing standard .NET libraries by Ivo Balbaert (8/21/2009 4:16:35 PM)

    The solution for the problem cited above is:

    replace let! rsp = req.AsyncGetResponse()
    by
    let! rsp = Async.BuildPrimitive(req.BeginGetResponse, req.EndGetResponse)

  • RE: F# Webcast (IV.) - Developing standard .NET libraries by Eralp (11/3/2009 1:23:21 PM)

    Thanks for all things , Dear Tomas!
    I will share this information with F# manias @ Turkey.

    Thanks again.

    Eralp

  • RE: F# Webcast (IV.) - Developing standard .NET libraries by Noli San Jose (12/6/2009 2:04:21 PM)

    Thanks for this series. More!!! Part 1 in itself is amazing in its simplicity but really eye-opening.

  • RE: F# Webcast (IV.) - Developing standard .NET libraries by Mike (3/23/2010 5:54:07 PM)

    Async.Run doesn't seem to be in VS 2010 - using intellisense Run is not in the choices.
    Seq.of_list is now Seq.ofList

    Nice videos - have ordered the book on the strength of them - very useful

  • RE: F# Webcast (IV.) - Developing standard .NET libraries by Tomas (3/24/2010 9:10:37 PM)

    Mike: Yes, some functions have been renamed (such as Seq.ofList), however, Async.Run should still be there!


Send comments to this article

Comments for this article have been disabled. You are welcome to send additional comments using email.