This problem has appeared before, and will no doubt keep appearing.

I haven't written a major F# app yet, but here is a synopsis of my own experience, and what I've seen of discussions here.

The choices seem to be:

1. Code it in F# from first principles. This is not hard, and is described in the primary F# sourcebooks and tutorials on the web. The problem is the obvious lack of a designer support to help you with layout, fonts, code generation, etc.

I use a Visual Studio solution with an F# project as the item under development. I also keep a C# project open as a "scratchpad" where I can experiment with layout and GUI items. I just convert the C# items to F# by hand.

This enables you develop your GUI with F# interactive (fsi).

2. The mixed language project. Use the GUI tools to develop a C# (or VB) project for the front end, and hook in F# code, as desired, for data processing.

The "hook" is achieved via DLL's, and the Visual Studio Solution/Project system. It does work smoothly, and I posted a couple of toy samples here and here.

This (the mixed language project) is the method endorsed and (apparently) used by the Microsoft F# team.

I have done some prototyping with this method, and found that it works. However, I have also found that switching thinking between C# and F# takes a lot of the fun out if. From my industry experience, I can see this working for large projects, where individuals, or whole teams, spend most of their day working in one language, and one subsystem, but I have doubts about it for smaller teams and projects. I personally am reasonably competant at both C# and F#, but I find it very difficult to be profficient, and current, with both. (not to mention HTML, CSS, WPF, ASP, and the whole alphabet soup)

So, in short, "How to convert a C# windows form to F#", I would recommend:

Don't write it in C# then convert to F#, but either: write it in F#, and use C#, and the forms designer, to protype code excerpts, which you convert to F#; or, use a mixed language project, as recommended by Microsoft.

(Just as I finished this post I discovered John Liao's Blog, which seems to have a lot of nice F# code for Silverlight and WPF.)

By on 7/21/2009 4:37 PM ()

Thx for the reply, im gonna try wat you've just wrote.. the thing is.. F# dont have a software that is actually like Vb/C# coz even though i read John Liao's blog, well thing is u still can't use it in a Database application where u need lots of textboxes and labels and command button and other things.. i will spend so many hours just coding the interface and no time writing the codes to make it functional.. LOL..

By on 7/22/2009 7:59 PM ()

well thing is u still can't use it in a Database application where u need lots of textboxes and labels and command button and other things..

The most sensible approach was already mentioned - leave the GUI stuff in the C# WinForm and separate the "business logic" out into a separate class library. That may require some refactoring of the application. Once your separated the two, you can re-implement the class library in F#.

You may want to have a look at F# Webcast (IV.) - Developing standard .NET libraries.

By on 7/23/2009 9:09 AM ()

i will spend so many hours just coding the interface

Well, that is just what it is going to take ...

If this was my problem I would:

  • download FSharpSamples.zip
  • Analyze sampleform.fs in the Samples101 project in order to understand how to put a Windows Form application together in F#.
  • Start attempting my own Windows Forms applications, starting with simple elements like labels, text boxes, then attempting progressively more sophisticated designs.

With the basics you should be able to start porting the C# code gradually over to an F# Windows Form. You will also have to port all the code in the "designer" files - you are responsible for managing all this code in F# yourself as there is currently no F# Forms Designer (there might be in the VS2010 beta but I don't know).

By on 7/23/2009 8:06 AM ()

>> no F# Forms Designer (there might be in the VS2010 beta but I don't know).

No, there isn't, and F# is also not available as an option for ASP.NET web sites. The release notes for the beta say that Microsoft recommends C# and VB for the front end.

By on 7/24/2009 2:43 AM ()

F# is also not available as an option for ASP.NET web sites.

While ASP.NET web sites are not available, ASP.NET web applications can be done the same way you can do WinForm applications - by hand (i.e. without a designer).

Currently I have problems with the FSharpAspNetCodeProvider in 1.9.6.16 but the one from 1.9.6.2 works. You can do both single file and code behind. The basics can be found in Expert F# Building Web Applications and also F# Support for ASP.NET and Notes on Samples. For ASP.NET MVC see ASP.NET MVC with NHaml - F# Edition.

By on 7/24/2009 5:19 AM ()

Hi fogless, thanks for responding. Good luck with it all!

Javaman

By on 7/23/2009 12:40 AM ()

There are some samples here, under ``GUI'':

[link:www.codeplex.com]

By on 7/20/2009 9:50 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper