Question

1) Are functional languages suited for web applications development?

2) Are functional languages suited for business/ERP/CRM type of applications?

Was it helpful?

Solution

Functional languages of the kind you describe are general purpose programming languages, they're used for all manner of things, including web apps and business apps. (I use Haskell).

As gabor implies, ultimately it comes down to libraries. Scala has a web framework: lift. Haskell has happstack, as well as 2100 4400 (in 2010 2012) libraries on Hackage for all manner of thiings.

It really isn't so much a question of the language, as the toolchain, when considering particular specialized domains.

OTHER TIPS

Functional languages are good for anything you would like to use them for.

However, developing applications these days are not as simple as using a programming language. The advantage of Java, C#, etc. is that they come with large libraries and other environment niceties that are absolutely required when you build business software. Most functional languages do not have that great support (as yet?).

F# might be promising since it's in the .NET environment and can take advantage of the tools available there (correct me if I'm wrong).

This article describes how Lisp, an early functional language, was used to create a web based application successfully.

Functional languages are well suited for web application development, Scala in particular.

Have a look at the Lift framework for more information.

2) Are functional languages suited for business/ERP/CRM type of applications?

To address the second point about business/ERP/CRM apps: personally I wouldn't implement these in a "pure" functional language like Haskell, or a dynamic functional language like Clojure. On the other hand, I am currently implementing an ERP in Scala, which of course is hybrid OOP/FP and statically compiled.

The reason I say this is that a business app like an ERP is fundamentally record-oriented: there is a data schema expressing the different record types and the app logic is then designed almost wholly around CRUDing those records and applying custom business workflows to them. And fundamentally, I don't believe that these sorts of data-centric business apps are a great fit for the functional model.

People can talk about the OOP-relational mismatch all they like but ultimately both OOP and databases are record-oriented: an OOP language with a good ORM lets you map those different data models into your code and then attach the code to handle each of the models. And having this statically typed (ideally with a strongly-typed ORM like Scala's squeryl) massively reduces the chances of a runtime error or e.g. a change to one of the data models not being properly applied through the code.

Don't get me wrong - I'm a big fan of FP (I'm doing more and more of my systems programming in Haskell), but for me the record-oriented approach of OOP makes more sense than the function-oriented approach of FP for wrangling the data objects of a business ERP or similar. (Scala is a nice exception to the rule because you get to use the OOP paradigm with quality ORMs for the record manipulation, but also the FP goodness for your general app programming.)

  1. Yes, Nitrogen is a good example of a functional web framework. It scales also.

http://nitrogenproject.com/

Yaws is a fantastic web server for Erlang.

While I wouldn't say that any particular functional languages are tailored for doing web-development, I also wouldn't say that you can't do web development with a functional language. I think that depends entirely on what web frameworks may be available for the language you choose and whether or not there are any web servers that will support the language.

For instance, I'm sure that you can use F# along with ASP.Net on IIS to do web development. I doubt there's support for F# in the templating engine, but you can definitely write business logic in F#.

Similarly, there's mod_haskell for Apache, which should make it relatively easy to have dynamic output with haskell. Although, I've never personally used it. At the same time, if there's a mod_(erlang or scala) for Apache, it would be similarly easy for those languages.

Ultimately, I think that the stateless nature of functional languages should make it well suited for a stateless, MVC style web framework. However, I think it really comes down to what tools and frameworks are available to make your life easier when working with these languages. For example, Ruby wasn't really popular for web development until rails got popular, and I didn't really like doing anything webby with Python until I found django.

Functional languages provides new kinds of abstractions which can be used for web development. Continuation based web servers are for example popular among functional languages. The PLT Scheme web server supports this kind of web application development. You can read more about continuations and their use in web development on wikipedia

Most functional languages, namely the ones you included, are considered general purpose languages. For web development, I would deeply consider using Clojure, or Scala. They both have very good web frameworks, and they both run on the JVM. I can totally recommend Clojure and Scala, but not so much for the others.

Haskell has a web framework, but I have never used it.

Business applications? Sure, why not. Functional languages are great for just about anything.

One of the biggest advantages claimed by proponents of functional languages is that they make it easier to write programs that can execute in parallel. But web applications typically don't have problems with parallelism. Typically, the web server/application server maintains a pool of threads, and each user request is assigned to a different thread, which can run on a different physical processor. So, you can take advantage of multiple processors without too much trouble. The trick is that web apps are characterized by large numbers of small requests, and threads and imperative languages work well there. Where imperative languages start to break down is when you have a small number of computationally expensive requests.

Another big advantage of functional languages is that since functions have no side effects, testing is easier. You test each function in isolation across a few of its inputs, and you know the system will work. But, there's a catch. If your operation involves input or output, you use a monad rather than a function, and you lose this testability benefit for that portion of your code.

But, typically web applications involve reading information from a request, making requests to a database, reading the response from the database, and formatting a response. That's lots and lots of IO, or monads, and very little opportunity for functions.

Given these characteristics of web applications, what benefits do functional languages bring to web application programming?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top