Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I try F# with MVC3 and ASP.net?

I am working on a new project for contract. Usually I go with c# asp.net and razor. The problem is, my portfolio says. C# C# C# C# over and over. I figure portfolio wise it may be helpful to have a little more variety. The other side is, a functional language seems to be an interesting approach since asp.net MVC3 is very function oriented as far as the controllers are concerned. So, has anyone tried using F# for this and did it turn out to be helpful or just get in the way?

I ask, because the controllers seem to benefit from being functional, while the models seem to benefit from an object oriented language.

like image 981
brandon Avatar asked May 18 '11 22:05

brandon


1 Answers

I wrote some examples of using MVC3 with a mix of F# and C# and it works quite well and I also created a template that can be used as a starting point (which should appear on Visual Studio Gallery soon):

  • F# Empty Web Application

There are some nice things about using F# in the implementation of model/controllers:

  • F# types such as records make it very easy to implement the domain model
  • You can also use F# asynchronous workflows to implement async controllers (see this snippet)

A slightly annoying thing is that the support for LINQ in the current version of F# is a bit limited (writing complicated queries with lots of joins and grouping isn't easy). However, you can nicely use dynamic operator if you're calling stored procedures (see for example this blog post).

(I also wrote some articles about this that are not published yet - I can send you a draft if you drop me an email at [email protected])

like image 187
Tomas Petricek Avatar answered Sep 20 '22 14:09

Tomas Petricek