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?

6
  • 5
    If you don't specify requirements, it's impossible to tell. Just throw a coin or something like that.
    – Vitor Py
    Commented Mar 6, 2011 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. Commented Mar 6, 2011 at 17:37
  • 1
    @Matthew: Facebook uses Erlang for its chat system, presumably for its massively parallel qualities. Commented Mar 7, 2011 at 3:33
  • 3
    Yessss, use Lisssssssp.
    – Mark C
    Commented Mar 13, 2011 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'. :) Commented Mar 15, 2011 at 12:48

5 Answers 5

20
+50

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)

5
  • 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
    Commented Mar 20, 2011 at 11:36
  • 13
    Erlang 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
    Commented Apr 4, 2011 at 23:25
  • @Berin as is always the problem with external links, it's now dead.
    – thecoshman
    Commented Mar 23, 2014 at 14:58
  • @thecoshman, My appologies... After 3 years I can't even recall the contents of what used to be on the page. Commented Mar 23, 2014 at 17:38
  • No worries at all :D ¬_¬ just never let it happen again. (before people freak out, I'm joking)
    – thecoshman
    Commented Mar 23, 2014 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.

8
  • 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
    Commented Mar 16, 2011 at 14:07
  • 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
    Commented Apr 4, 2011 at 23:27
  • 1
    @Jonas: there is for example vert.x vertx.io
    – vartec
    Commented Aug 30, 2013 at 12:08
  • 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
    Commented Mar 22, 2016 at 20:30
  • 1
    Like @sara, I resent your comment: Haskell is not academic and is used for real production software.
    – Andres F.
    Commented Mar 9, 2020 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.

1
  • its for a work type project. I am thinking it will probably be Erlang but I may do haskell.
    – Zachary K
    Commented Mar 17, 2011 at 13:48
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.