tags:

views:

579

answers:

5

I have been hearing about F# and Microsoft now have a guy who is blogging and coding away in redmond somewhere about it. Can you really write GUI code from F# (I'd love to see an example of say adding a button to a form and subscribing to the onclick event for instance)

Does F# have full access to all of .Net?

I'm honestly curious and I know I could google but I'd love to hear from someone who is really using the language.

+11  A: 

Yes, you can certainly write WinForms apps - although you wouldn't override the OnClick method, you'd subscribe to the Click event.

Yes, F# has full access to .NET, although you won't get very idiomatic functional code if you use a lot of mutable types.

Tomáš Petříček's F# web site has sample source code from his book (disclaimer: I'm involved with the book too, so I'm clearly biased) which has WinForms examples.

Jon Skeet
Thanks Jon, that was a really good read about each of the applications of F#, and actually a nice primer on functional programming in general. I especially like the comparison with C#. Cheers mate ;)
Spence
Not only does Jon Skeet dominate in reputation, he's also involved in a book. You, sir, are intense. I salute you.
Thomas Owens
+4  A: 

I'd highly recommend this excellent post by Scott Hanselman, which points to some F# resources including examples and presentations.

Leonardo
+1  A: 

I haven't actually used F#, only read the specs. It may be great for WinForms development, but my immediate reaction to this is "it doesn't really matter". As long as you use CLR compliant compilers you should be able to mix F# assemblies with others written in C#/IronPython/etc.

Yes, F# can use the .NET Framework, and F# assemblies can be used by other .NET assemblies.

My advice would be to code your functional libraries in F# and then use whichever .NET language you fancy to write the client app(s).

d91-jal
Thats what I figured, but what use is a language if you can't use it do everything you need.Another issue is that the compilers currently don't support multiple languages in the same assembly, so performance may suffer depending on what your doing in the code.
Spence
@Spence, if what you say was true, there WOULD only be one language. But different languages have different aims, uses, and strengths. You certainly won't catch ME coding an OS in SQL any time soon.
Benjol
+1  A: 

You CAN write GUI code from F#, but I'm not sure that you'd WANT to. If you are the kind who wrote your C# GUIs in notepad anyway, then it probably wouldn't bother you. Personally I prefer the designer, and there isn't one for F#, and as far as I've understood it, there isn't going to be one either - which probably says something about the intended use of F#.

But as Jon Skeet says, Tomas has some interesting examples (especially filtering/piping events), which show what I suspect may be a good cross-over point, i.e., design your C# GUI with designer, and then write the brains in F#, hooking one to the other with events.

Benjol
The GUI designer is the whole reason C# is such a pleasure to design in.
Spence
+2  A: 

But as Jon Skeet says, Tomas has some interesting examples (especially filtering/piping events), which show what I suspect may be a good cross-over point, i.e., design your C# GUI with designer, and then write the brains in F#, hooking one to the other with events.

That's I think a very good approach. Designing complex GUIs without WinForms designer is a bit annoying (though, the difference isn't that big in WPF - F# doesn't support WPF designer, but you don't loose that many things there).

Anyway, stay tuned for more examples :-). Using declarative event handling (Event.filter, Event.map & friends) is quite nice, but in some cases it isn't quite what you want to. I'm just writing a chapter about that and I think F# gives you some really awesome ways to deal with GUIs - the source code will be freely available on the book web site and I'll hopefuly write some short intro for my blog as well once the book will be done.

Tomas Petricek
Thanks for your input Tomas. I've been reading your blog over at MSDN. Didn't realise you were associated with Jon Skeet as well though. Small world out there...
Spence