30

I am looking to start an experimental project using a functional language and am trying to decide beween Erlang and Haskell, and both have some points that I really like.

I like Haskell's strong type system and purity. I have a feeling it will make it easier to write really reliable code. And I think that the power of Haskell will make some of what I want to do much easier.

On the minus side I get the feeling that some of the Frameworks for doing web stuff on Haskell such as Yesod are not as advanced as their Erlang counter parts.

I rather like the Erlang approach to threads and to fault tolerance. I have a feeling that the scalability of Erlang could be a major plus.

Which leads to to my question, what has people's experience been in implementing web application backends in both Haskell and Erlang. Are there packages for Haskell to provide some of the lightweight threads and actors that one has in Erlang?

Frank Shearar
  • 16,751
Zachary K
  • 10,413

5 Answers5

20

The only question I have is what is your web service doing? If the web service is truly a functional problem, then Haskell will be a better fit.

Erlang isn't necessarily a functional language. It's a procedural language with a very strong execution model for massively parallel systems. It was designed for the telecom industry, and it would definitely make an excellent fit for responding to web service requests.

See this page* for an overview of the differences between procedural and functional programming. (Apologies in advance for the ugly black on cyan page).

If your web service is doing a fair amount of pattern matching and applying rules, then Haskell is your choice. If you just want a scalable infrastructure that isn't too different from the languages you probably already know, choose Erlang.

(* link via Wayback machine. The original file has been removed)

10

Between the two you mention, definitely Haskell is academic, while Erlang is used in real-life high-scalability projects. So of the two for web services I'd choose Erlang.

But I'd say you have third choice: Scala, a language that is heavily influenced by both Haskell and Erlang. It's used to build top notch web services like Twitter or Foursquare. There is even Lift, a web framework inspired by Rails and Django, although with a bit different, more functional approach. Foursquare is using Lift.

vartec
  • 20,846
6

Usually i say: "learn things as far as possible from your zone of comfort, it will make you a better programmer even if you never use it in practice".

In this case, that could probably mean Haskell; but Erlang is not only becoming almost socially acceptable; but the main points (light processes, message passing, huge scalability) are coming on many other 'practical' platforms, so the lessons learned have big and immediate applicability on more 'real' work.

my advice: if it's for fun, do Haskell. if it's for training, go Erlang.

Javier
  • 9,958
1

You could also consider Rust.

  • It is not purely functional, but it encourages a semi-functional style
    • Closures
    • Immutability by default
    • It has a strong, safe macro system, allowing you to write macros (or use existing community-created ones) to write code in a more functional style
  • It has libraries/frameworks for every level of abstraction
  • It has a strong emphasis on efficient memory safety
  • It has a strong type system
  • It makes all sorts of concurrency really easy (as long as you meet all the safety requirements)
  • It has a large active community
  • It is open-source (like the others you mentioned)
  • etc.
1

Haskell(GHC) has out-of-the-box support for green threads (Erlang's 'processes'). For example forkIO spawns a new green thread and returns its thread id.

forkIO :: IO () -> IO ThreadId

message passing mechanism is implemented by the package distributed-process but it is not very well maintained.
Haskell's data-sharing mechanism differs from Erlang. Haskell embraces the idea of mutable global states and added abstractions to make it safe to use. A prime example of this is TVar (Transactioal Variable) which enables composable atomic transactions.
Haskell also has some very high-level web service libraries that make use of its expressive type system (dependent types), for example, servant. It allows you to specify your REST API using type-level DSL which can be used at compile-time to ensure type safety.

Edit:
apparently distributed-closure also implements closure serialization with the help of staticptr

Poscat
  • 111
  • 3