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,643
  • 7
  • 48
  • 84
Zachary K
  • 10,433
  • 2
  • 37
  • 55
  • 5
    If you don't specify requirements, it's impossible to tell. Just throw a coin or something like that. – Vitor Py Mar 06 '11 at 14:04
  • 1
    I have no proof of this conclusion, but Facebook's use of Erlang indicates to me that it is both powerful and reliable. – Matthew Read Mar 06 '11 at 17:37
  • 1
    @Matthew: Facebook uses Erlang for its chat system, presumably for its massively parallel qualities. – Robert Harvey Mar 07 '11 at 03:33
  • 3
    Yessss, use [Lisssssssp](http://www.youtube.com/watch?v=TRASn4tcXFE&t=0m02s). – Mark C Mar 13 '11 at 15:16
  • 8
    In an old Commodore 64 magazine, they had an article on fake languages. The best one was "Lithp", which was exactly like lisp, except that the 's' character was excluded. That forced all 'lithp' developers to substitute a 'th' for the 's'. :) – Berin Loritsch Mar 15 '11 at 12:48
  • @Robert Harvey: That's not a ringing endorsement for Erlang. I find Facebook chat to be flaky at the best of times and truly godawful the rest of the time. ;) – FrustratedWithFormsDesigner Mar 18 '11 at 14:56

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)

Berin Loritsch
  • 45,784
  • 7
  • 87
  • 160
  • It is going to be something that looks a lot like a social network. At this point there is a 90% chance it will be done in haskell. – Zachary K Mar 20 '11 at 11:36
  • 13
    [Erlang](http://en.wikipedia.org/wiki/Erlang_(programming_language)) is a functional language, not a procedural language. It has great support for pattern matching and it's unique pattern matching per bit which is very helpful when doing network services. – Jonas Apr 04 '11 at 23:25
  • @Berin as is always the problem with external links, it's now dead. – thecoshman Mar 23 '14 at 14:58
  • @thecoshman, My appologies... After 3 years I can't even recall the contents of what used to be on the page. – Berin Loritsch Mar 23 '14 at 17:38
  • No worries at all :D ¬_¬ just never let it happen again. (before people freak out, I'm joking) – thecoshman Mar 23 '14 at 19:00
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,760
  • 1
  • 52
  • 98
  • 2
    Agree with your answer, except for the very last sentence. Lift is very different from Rails. Rails is modular, Lift is monolithic. Rails is a MVC framework, Lift is not. Rails is object oriented, Lift is more functional. – dbyrne Mar 16 '11 at 14:07
  • @dbyrne: ok, edited – vartec Mar 16 '11 at 16:00
  • 3
    The problem with Scala for web services is that the most popular Java application servers scales really bad compared to servers written in Erlang and Haskell. – Jonas Apr 04 '11 at 23:27
  • 1
    @Jonas: there is for example vert.x http://vertx.io/ – vartec Aug 30 '13 at 12:08
  • Lift is no longer the de-facto framework for Scala. It is now [Play](https://www.playframework.com/documentation/2.3.x/ScalaHome), which is fully MVC and stateless. I agree with the answer. Scala is a better choice for real-world. Easier to get Scala developers than Erlang and Haskell. – Jus12 Oct 19 '14 at 05:15
  • @Jus12 [You may want to see](https://www.quora.com/Why-did-Typesafe-select-Play-for-their-stack-instead-of-Lift) – nawfal Oct 21 '15 at 02:33
  • 3
    I resent the sentiment that "haskell is academic and should not be used for real life-projects". it's used by a lot of big names like facebook and google, and there's a fair share of startups doing good with haskell too. there's nothing that prevents you from building whatever you need. – sara Mar 22 '16 at 20:30
  • 1
    Like @sara, I resent your comment: Haskell is not academic and is used for real production software. – Andres F. Mar 09 '20 at 20:18
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,888
  • 1
  • 26
  • 35
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.
Solomon Ucko
  • 408
  • 3
  • 10
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