WPF in F#

My blog has been quiet these days, for a few reasons, but mostly because I am excited about learning F#. In case you have never heard of it, F# is a new language being developed by Microsoft Research. Somasgear recently announced that Microsoft is investing heavily in F# and plans to make it a first-class .NET language, giving it full support in Visual Studio.

I was raised on C-based languages: C, C++, and C#. The concepts and syntax in F# are radically different from anything I am used to because it is largely influenced by OCaml, which is a functional programming language. F# is a hybrid of functional, object-oriented, and imperative programming languages.

Traditionally functional programming has been used for math-intensive programming problems; like financial analysis, and scientific computing. I’m not interested in learning F#, or functional programming, for that reason. What I want to know is if F# can be useful in the area of WPF programming, or, more generally, in front-end development. Are there sweet spots where F# and WPF will work together much more naturally and less verbosely than, say, C# and WPF? If so, what are those sweet spots and how can I introduce F# into my normal development workflow? If not, why not?

Robert Pickering, the author of the only F# book currently on the market, has posted some entries on his blog which use WPF and F# together. They’re not particularly useful examples, but interesting nonetheless. You can find them here and here.

Do you have any experience using F# and WPF together? If so, I’d love to hear more about it.

7 Responses to WPF in F#

  1. I would be interested to know what you consider “useful”🙂

    In all seriousness I’d like to improve, I’ve not done a huge amount of work with WFP, so let me know what you think is missing. I agree my samples only scratch the surface of what’s possible in WPF, but I actually thought I’d covered the fundamentals of what you need to get going in WPF i.e. loading and showing a xaml file and retrieving and manipulating objects from it. After that exploring the possibilities offered by WFP is an exercise for the reader …

  2. Josh Smith says:

    Hi Robert,

    I didn’t intend on criticizing your work with WPF and F#. I think it is *very* cool stuff.

    If you are curious about what I mean by “useful” then just check out my blog posts and CodeProject articles:

    http://www.codeproject.com/script/articles/list_articles.asp?userid=247684

    I generally try to stick with writing about things that either have helped me solve a problem in WPF, or porting a solution from WinForms to WPF. I’ve never needed to make a picture of a cat wobble and shake in 3D. 😀

    I’m reading your “Foundations of F#” book now and am learning a lot from it. Nice job!

    Thanks,
    Josh

  3. Fran says:

    Josh, often making things clear is useful enough, even if you have to bend a cat…

  4. Josh Smith says:

    Fran,

    I suppose there’s more than one way to bend a cat. 🙂

    Josh

  5. I think the great thing about F# is that 99% of you’ve learn about how to do WPF in C# is directly transferable to F#. So F# users can already benefit from the welth of information provide by you and others in the WPF community. I guess the reason for providing specific F# samples is about a) getting people going so F# users aren’t faced with having to start completely from scratch and b) trying to provide some guidance on what is good style when working with this API.

  6. Josh Smith says:

    Robert,

    I’d like to add: c) to let people know that it’s even possible to program WPF with F#.

    Considering how foreign of a language it is, I think it’s necessary to show real examples of using F# with WPF just to say, “Look here, it’s possible folks!”

    Josh

  7. Cool stuff. Let us know if you come up with any extravagant Josh Smith-style F# + WPF stuff.🙂

%d bloggers like this: