Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# and ASP.NET

is it possible to write ASP.NET (MVC) applications with F# code? If yes, how? What possible benefits would this provide?

Thanks.

like image 375
pistacchio Avatar asked Jul 16 '09 07:07

pistacchio


1 Answers

Yes. In fact, we're just finishing an app using ASP.NET MVC and NHibernate, with F#.

It's pretty easy: create a C# ASP.NET MVC app, then create an F# library, and put all your controllers in the F# library. (F# doesn't have a ASP.NET project type yet.)

The benefits are the same as usual -- everything F# provides. Of particular note is how short the controller code becomes. The type inference is just excellent.

If you want to use F# record types with the MVC binder, you'll need a bit of helper code. I wrote about it here.

However, with the 1.9.6.16 release, The F# ASPNetCodeDomProvider has some bugs, making it unsuitable for use in the ASPX pages. Also, IntelliSense doesn't work there. So, for the ASPX part, we used C#. Not a big deal, as that's just usually wiring up the model to the view.

like image 53
MichaelGG Avatar answered Oct 04 '22 21:10

MichaelGG