Friday, February 27, 2009

Haskell or Erlang?

I've coded in both Erlang and Haskell. Erlang is practical, efficient, and useful. It's got a wonderful niche in the distributed world, and it has some real success stories such as CouchDB and jabber.org. Haskell is elegant and beautiful. It's been successful in various programming language competitions.

I have some experience in both, but I'm thinking it's time to really commit to learning one of them on a professional level. They both have good books out now, and it's probably time I read one of those books cover to cover. My question is which?

Back in 2000, Perl had established a real niche for systems administration, CGI, and text processing. The syntax wasn't exactly beautiful (unless you're into that sort of thing), but it was popular and mature. Python hadn't really become popular, nor did it really have a strong niche (at least as far as I could see). I went with Python because of its elegance, but since then, I've coded both professionally.

I feel like I'm in the same situation again. Erlang is clearly successful and useful, but its syntax is not so wonderful. Haskell is profoundly elegant, and perhaps even higher level, but it doesn't seem as popular, nor does it seem to have success stories as great as Erlang does.

Another interesting thing to note is that Erlang is really good at Erlang-style concurrency. Haskell doesn't have the same zen in this field as Erlang has, but Haskell has successfully tackled a wider variety of approaches to concurrency--at least, that's the feeling I get when I read this page.

Is there anyone out there who enjoys Python's elegance as much as I do who can give me some advice on committing to either Erlang or Haskell? Am I too far ahead of the curve in my hopes to one day code professionally in one or the other? Should I just wait for Reia? Have any mere mortals such as I had success with reading Real World Haskell? Should I take a break from playing with weird languages and do something useful, like write a Facebook app or an Android app?

65 comments:

Anonymous said...

erlang

eGlyph said...

My not so humble opinion is to take 'em both. I'm a long time reader of yours and 100% sure you'll handle it.

My recommendation to you is to get a copy of Joe Armstrong's 'Programming Erlang', which is a killer book for anyone interested in getting started quickly, while
'Real World Haskell' is your key to the Haskell world.

Travis Jeffery said...

What about a third option -- just sticking with what you know. What are your reasons from moving away from Python?

Tomas A said...

I'd say Haskell seems to be useful for a wider range of applications than Erlang. If you're primarily interested in doing heavily concurrent applications, definitly go for erlang. Haskell's concurrency is sweet, especially STM, but not even near erlang when it comes to efficiency.

For most other tasks though I'd go with Haskell.

Sebastian Sylvan said...

I wouldn't be so quick to say Erlang is more efficient than Haskell when it comes to concurreny. Haskell is natively compiled, with static types, after all.

Other than that I think you're right, Erlang is a bit of a one-trick pony. It does message passing really well (though IMO most of its benefit is just that it has a little bit of syntactic sugar), while Haskell supports message passing, shared state (with STM or traditional locks), task based parallelism (Control.Parallel.Strategies), and recently nested data parallelism.

So IMO, Haskell will only get more and more attractive because it supports a wide range of solutions to the concurrency/parallelism problem, while other languages usually only support one (or none!).

Vincent Foley said...

Write an Android app... in Clojure!

Hugo Gomes said...

It is always good to try out new and different things.

Haskell seems to be more recent than Erlang, so i would go for it if i had the spare time to learn a new language.

shapr said...

I'm a big fan of Haskell, but Erlang is definitely worth learning. I jumped from Python to Haskell as my primary programming language, and the conversion went smoothly for me.

I don't know how to compare the popularity or commercial possibilities of the two languages. I can say that Boston has five companies doing Haskell work.

I can also say that when I lived in Sweden two years ago, there was lots of commercial Erlang work available there.

So, they both seem like professional opportunities to me. I think you should pick one to start, and come back for the other one later.

I'm biased towards Haskell, but that's because I like the #haskell irc community so much!

Jim said...

I will swim against the tide here and suggest Erlang. It does not have the overall "sweetness" of Haskell, but if you want a "good tool for any job" language you would be better off diving straight into the Lisp pool. Erlang is better than Haskell for the types of problems you probably want to be dealing with for the next five or ten years as we move to a message-based massively concurrent world. Don't give up on Haskell, but spend more time on Erlang.

Darrin Eden said...

Excellent question. Personally, I like to define an interesting problem and then consider language.

Language for language sake is neat as well, but then maybe implement a compiler/runtime at that stage? Ask yourself which language would you have the most to learn from the implementation?

To your point - I'd suggest picking one of the Amazon-hosted public data sets, develop an interesting question, then reconsider your choice.

Good luck!

Sergey Kishchenko said...

Both of them. Erlang is simple and cool, Haskell is powerful and cool. Choose the 'current' language on per-problem basis. And don't forget about Python :)

ToddB said...

I have been wondering same thing myself. I have the programming erlang book haven't really went through yet. Though for me its between F# and Erlang. Luckily I have just started a new appengine project, and from there I may branch back into Moo or Inform 7 programming for fun.

Shannon -jj Behrens said...

Clojure? Weird. Now I'm even more confused ;)

Shannon -jj Behrens said...

I definitely think that right now, Erlang is the more immediately useful--just as Perl was more immediately useful in 2000. However, I picked Python back then, and I don't regret spending more time with Python than Perl.

I'm definitely a fan of learning multiple languages, which is why I've played with both Erlang and Haskell. However, I'm still having a hard time committing to one and making it a core skill.

Shannon -jj Behrens said...

> My not so humble opinion is to take 'em both. I'm a long time reader of yours and 100% sure you'll handle it.

Thanks for the vote of confidence, eGlyph ;)

Shannon -jj Behrens said...

> What about a third option -- just sticking with what you know. What are your reasons from moving away from Python?

1. I get bored if I'm not learning something.

2. Python actually can't do everything.

3. There is a certain class of applications where Haskell and Erlang really excel.

Krishna Srinivasan said...

How about just getting back to Scheme ? (Little Schemer series). :)

That way you can easily implement the language you want. Or at least a quick front-end to whatever you want your language to compile to.

Paul Bonser said...

With HiPE, Erlang is also natively compiled.

I'd agree with "both", but I'd say start with Erlang. It looks funny and takes some getting used to, but you can do some pretty cool stuff with it.

Erlang has a lot of the functional features that Haskell has (pattern matching, list comprehensions, guards, single assignment), and would actually work as a stepping stone on the way to some of the more crazy ones like lazy evaluation and monads.

Anybody who tells you that Erlang is only good for doing things with concurrency isn't familiar enough with Erlang to be giving you advice about it :)

Hot code swapping and fault-tolerance are even more important features which come in very handy when developing long-running applications.

Erlang is especially well suited for web applications due to this feature. If you're interested in writing those, check out MochiWeb or Erlyweb. I like MochiWeb better, because it's much lower-level and less overhead, but that's just me.

Jason Dusek said...

Some other posters have suggested that Haskell's concurrency is not as efficient as Erlang's; however, this is not an apples to apples comparison. Haskell allows millions of threads and can efficiently parrallelize a map operation, for example; Erlang has a richer process model, with monitoring and hierarchy and individual mailboxes; but these individual processes are rather more expensive.

Because Erlang's processes offer addressing and monitoring, they are good fit for modelling a distributed system; it is an open question whether it is easy to make these features available as a library in other languages. However, I can assure that bolting a rich type system and elegant syntax on to Erlang would be painful indeed.

Haskell has broadened my horizons more than any other language; it has opened my eyes to the degree to which computers can verify our programs and how we can use that to speed our work.

Jason Dusek said...

It's so sad to see people arguing for Python with "Stick with what you know.". Just ride out these new languages, they're a stupid fad! Ten years ago, that's not the kind of talk you heard from the Python camp. That was the kind of talk you heard from the KSH camp.

gaspode said...

Erlang, then start contributing to CouchDB and get involved again with open-source projects instead of just using them (yes, I know you did plenty back in the day, but that was a long time ago!). :)

Philip Jenvey said...

Haskell is really nice, but in the immediate future I see it being under the radar at most businesses, i.e. there won't be many chances to use it on the job (if that's important to you). Monads, lazy evaluation, et. al scare people

Erlang has some quirks, and although it excels at concurrency I wish it was a faster VM

I'm also keeping an eye on Scala, it's getting more use in the Java world and I like the type inference, and it's fast

Clojure is another elegant language, but is very new to the stage -- but worth keeping an eye on

rgz said...

Erlang eschewing of typing, concurrency idioms and monitorable proccess make it better at whatever I would really need a functional ├▒anguage for *while* at the same time being able to do anything Haskell can.

Haskell seems like the type of language you'd use to use Haskell, that's it, the language for the language sake.

Shannon -jj Behrens said...

> How about just getting back to Scheme ? (Little Schemer series). :)

It's not a bad idea, but I finished watching the SICP videos. Haskell and Erlang come from the same lineage, but they both have some additional benefits, imho.

Shannon -jj Behrens said...

> Erlang is especially well suited for web applications due to this feature. If you're interested in writing those, check out MochiWeb or Erlyweb. I like MochiWeb better, because it's much lower-level and less overhead, but that's just me.

Anything that Bob Ippolito does can't be half bad ;)

Shannon -jj Behrens said...

> Erlang, then start contributing to CouchDB and get involved again with open-source projects instead of just using them (yes, I know you did plenty back in the day, but that was a long time ago!). :)

Ouch! Isn't this blog worth something?

Shannon -jj Behrens said...

> Haskell seems like the type of language you'd use to use Haskell, that's it, the language for the language sake.

Well, to be fair, I use Python just because it's Python. There's something beautiful and elegant about it. It's not as cheap a hosting solution as PHP, nor is it as popular for Web programming as RoR, nor is it as fast running as even Java, etc. However, it sure is pleasant to code in ;)

That's why I naturally lean toward Haskell, even though Erlang seems more practical.

Shannon -jj Behrens said...

Ok, now that I've read all the comments, I still don't see a clear winner ;) *sigh*

It's one thing to know a language, but it's another to be an expert. I'm having a heck of a time trying to be an expert of Ruby and Python. I was an expert of PHP, but I gave it up. I've never seriously tried to be an expert of Perl. My Java skills are slowly rusting away--I haven't used them since the 1.3 days.

The problem seems to be that the fast I learn something, the faster I forget something else ;) That's why I was trying to pick something to really focus on next.

Shannon -jj Behrens said...

Philip, thanks for the link to: http://damienkatz.net/2008/03/what_sucks_abou.html

That was an awesome read! It confirmed a lot of my early complaints and went a lot further.

Since the success of CouchDB is a huge telling point in favor of Erlang, hearing his sobering comments on some of Erlang's downsides is quite useful.

Alec said...

What about OCaml? Only half-kidding. Some folks at work (yes... ) gave some presentations on OCaml & Monads and I was pretty blown away. Talk about a TOTALLY different way of thinking.

Shannon -jj Behrens said...

Me and Ocaml have a long and sordid history. I think of Ocaml as the C++ of the functional world ;)

Shannon -jj Behrens said...

shapr, can you tell me more about your transition from Python to Haskell? Did you read "Real World Haskell"? If so, was it good? Do you feel comfortable with more advanced Haskell topics? How long did the transition take? Do you feel that Haskell is particularly helpful for certain things in your production coding that Python would make more difficult? I prefer Haskell in theory, but in practice I still really prefer Python, so I'd love to get a Python programmer's perspective. Thanks!

Shannon -jj Behrens said...

Writing an Android app for Clojure is indeed a pretty entertaining idea. Unfortunately, I don't think it's currently possible: http://groups.google.com/group/clojure/browse_thread/thread/cf9c928f0027836a

I may be wrong. That post is from 2007.

Noah Gift said...

Or you can just write your own language....

How old was Guido when he wrote Python? Wasn't he a little younger then us?

Shannon -jj Behrens said...

I've been looking at Python compared to other languages like Java, Ruby, Erlang, Haskell, ML, etc. Although the performance of Python is worse than Java, Erlang, Haskell, and ML, it's still better than Ruby. Better yet, it looks like Python requires fewer lines of code than Java, Erlang, Haskell, and ML. Ruby ties Python in number of lines of code.

Correct me if I'm wrong: http://shootout.alioth.debian.org/debian/benchmark.php?test=all&lang=python&lang2=hipe&box=1

Since I mainly focus on programmer productivity, I don't see anything hugely more productive than Python.

Shannon -jj Behrens said...

It looks like MLton Standard ML totally smokes both Haskell and Erlang in terms of performance:

http://shootout.alioth.debian.org/debian/benchmark.php?test=all&lang=ghc&lang2=mlton&box=1

http://eric_rollins.home.mindspring.com/erlangAnt.html

B. said...

I like Haskell because its elegant. What bugs me about it is that doing performance tuning can turn a nice program into something ugly. It's getting better, IMO.

The recent Monad.Reader talks about a "Strict Haskell" trick which makes me happy since I prefer selective laziness over selective strictness. Personality defect on my part?

This, and performance, is one reason why at heart I've been more in the MLTon/SML camp (Not ocaml). However, I find the ML restrictions from its notion of Hindley-Milner typing annoying enough to keep me away from doing serious work there. I keep reading about more expressive changes to the type system (a la Alice) but am wanting something more MLTon than the VM used by Alice.

(Quick story -- I once glued my version of "stackless" python with MLTon and was making calls both directions ... until OOPS the GCs on either side began running. On my list now: investigate region-based memory management or something!)

Has anyone toyed with Clean? That appeals to me but I think GHC plus a bunch of up-and-coming complier tricks will make this language obsolete.

As for erlang. Alas, I want to take time with the language because I think its an awesome platform for distributed computing. But the language itself does not intrigue me enough to engage without some project to propel me onward.

Shannon -jj Behrens said...

Brennan, you are a gentleman and a scholar! Thanks for taking the time to comment.

It's strange that Haskell, MLton, and Erlang are all amazing for some reason, but seriously flawed in another way. Haskell doesn't perform as well as MLton. MLton has type flaws that you mention. Erlang has crufty syntax, lacks an ML type system (which may or may not be a flaw depending on your opinion), and can't compile down as low as Haskell can (because of its types).

You suggest that Alice, which I really liked the last time I looked, doesn't have a wonderful compiler like Haskell.

You said, "I prefer selective laziness over selective strictness." Doesn't that match Ocaml? Ocaml is a bit of a turnoff to me too. I spent a lot of time playing with Ocaml a few years ago.

I think I'll look at Alice and Clean again.

I agree with you on Erlang too. It's concurrency model is really neat, but since I know enough Erlang to know some of its warts too, it's hard to commit to it without having a serious project in mind that would benefit from it.

Please keep me updated if you come to any major conclusions.

Shannon -jj Behrens said...

I took a look at Clean:

The code looks like Haskell.

"Clean is the only functional language in the world which offers uniqueness
typing. This type system makes it possible in a pure functional language to
incorporate destructive updates of arbitrary data structures (including
arrays) and to make direct interfaces to the outside imperative world."

"The Clean System is available on many platforms (PC, Mac, SUN) and operating
systems (Windows'95/'98/2000/NT [it's old!], Linux, MacOS, Solaris)."

"The new version 2.0 of the IDE is currently only available on the Wintel
platform."

Shannon -jj Behrens said...

By the way, I just bought "Concepts, Techniques, and Models of Computer Programming" which is touted as the next SICP. Looks awesome ;)

Shannon -jj Behrens said...

"Alice ML is a functional programming language based on Standard ML, extended
with rich support for concurrent, distributed, and constraint programming.
Alice ML extends Standard ML with several new features."

It has libraries for GTK, SQL, XML, etc.

It uses a VM with a JIT.

It sounds to me like an Erlang'ish version of ML. I must admit that I like the syntax better than Erlang ;)

Anonymous said...

This choice seems rather clear to me, if you want to program highly concurrent, fault-tolerant well-scaling applications, where uptime is mission critical (code swapping, OTP etc!) use erlang. For everything else, Haskell is probably just as good. Granted, the Haskell syntax is much sweeter, but it always seemed a bit more academical than practical to me, and erlang also has great syntactical features (look at the binary pattern matching, for instance!). Also, I think the BEAM VM erlang uses is very interesting and has a lot of (yet) unused potential. Transaction based memory is a joke, imho, as long as its not going to be implemented on the hardware side, and it still doesn't really solve your concurrency problems - imho the way erlang does parallelisation really is the way to go here.
Someone should port Haskell to BEAM :D

erlang_blogs said...

Erlang, because if you want friendlier syntax you can use Reia

Travis B. Hartwell said...

It is currently possible, at least at a prototype-level, write an app for Android with Clojure. I should have made an announcement on the clojure mailing list or something. Rich Hickey helped me through some issues in both Clojure core and in my code and I ported a hello world application from Java to Clojure:

http://github.com/Nafai77/helloandroid/tree/master

I haven't had the time to do more than that app. I've verified that it runs in the emulator and on an actual physical device, but it is really slow to start up -- like on the order of 10s or something.

I'm not sure if anyone has pursued things beyond this, as I haven't had time to focus on Android development at all.

Shannon -jj Behrens said...

> Erlang, because if you want friendlier syntax you can use Reia

I'm watching Reia, but it's definitely not ready for production yet. As cool as it is, it's still at the experimental stage, imho.

Shannon -jj Behrens said...

> It is currently possible, at least at a prototype-level, write an app for Android with Clojure.

Travis, thanks for the update.

You heard it folks! If you want the latest news on Clojure, look no further than the comments on my blog ;)

Daniel T said...

I am/kind of was in a similar situation. I like Python a lot but want to learn a more functional language. To be honest, Erlang never really got me very excited simply because it looks so strange (though I'm sure it looks less strange once you program in it a lot...kind of like Lisp, supposedly). So I guess that made it an easy choice for me. I just got my copy of RWH today, but since I'm in grad school, I doubt I can give feedback on it in a timely manner.

Though, I do plan on learning Erlang later on. To me, I guess practicality doesn't come into play much since my research is on the OOPL side, rather than FPL. I have no need (as of now) to write uncomfortably parallel programs, so I figure it's better to learn Haskell, which seems to be more elegant than other FPLs (obviously IMHO), before diving into the world of concurrency, which is totally exciting...on its own.

Anonymous said...

The shootout benchmarks you are looking appear to be out of date. It says "Most recent measurement: late 2007" on this page
http://shootout.alioth.debian.org/debian/
Try starting from this page
http://shootout.alioth.debian.org/
and look at the Ubuntu measurements.

Shannon -jj Behrens said...

Thanks!

Martin Krauskopf said...

Great reading (all the comments), been having the same dilemma (started to read RWH recently).

You have mentioned that you bought CTM, so other obvious choice is (not mentioned so far?) Mozart Oz? :) - the language of the book.

Shannon -jj Behrens said...

Yep. So far I'm loving the book, and I'm loving Oz. Compared to Haskell, Oz doesn't have an ML type system (it's more like Lisp), and it doesn't perform as well. However, I really like the whole multi-paradigm thing. That's one of the reasons why I like Python so much.

llaisdy said...

Very interesting discussion.

I'm a Python hacker. I started reading Real World Haskell in May. Looking into a chat application to use with Django, I bumped into the fact that Facebook's chat application is written in Erlang. So now I'm fretting about Erlang too. What makes it worse is that Programming Erlang looks like a really good book (I think RWH is a very good book deep down, but it could have done with another six months preparation and proof-editing).

It looks like I'll be learning Erlang after reading this discussion.

Best wishes

Ivan

Shannon -jj Behrens said...

I also think that Scala is an interesting option. The Twitter guys made a pretty compelling argument for why Scala is a better option than Erlang. Since Scala runs on the JVM and has access to its libraries, it's probably easier to bootstrap into production. However, I don't think Scala has a lot of the stuff that's present in Erlang/OTP. In the short term, I have to focus on some down-to-earth Rails stuff. In the longer term, I'm hoping to finish "Concepts, Techniques, and Models of Computer Programming" because it's applicable to Erlang, Haskell, and Scala. If I actually had to do some programming such as a highly-concurrent network server, I'd probably give Scala a shot.

Anonymous said...

FalconPL could be a great alternative since it's multi-paradigm and multithreading. And one feature very interesting is its C dynamic library interface which allows to load and use directly a C shared module on the host system (they're working over C++).

http://falconpl.org/index.ftd?page_id=facts

ajxn said...

I guess you are not that accustom to Erlang syntax is becouse you have no experiance of Prolog.
If you look at http://www.sics.se/~joe/pubs.html for the paper "Use of prolog for developing a new programming language.
J. L. Armstrong, S. R. Virding and M. C. Williams The Practical Application of Prolog" "
You will know a little bit more about where Erlang comes from. A fun paper, wich I might use later :)
(Yes, Joe Armstrong is one of the main architectur of Erlang. And yes, Prolog is a great langugage)

Shannon -jj Behrens said...

Unfortunately, I didn't get a chance to code in Prolog in college.

I think it's fair to say that Prolog itself has weird syntax since it's simply an objective fact that languages with C-like syntax are orders of magnitude more popular. Personally, I prefer Python's syntax ;)

However, on the subject of Prolog, I've been coding in Oz lately, and Oz was heavily inspired by Prolog. Neat stuff!

Thanks for the comment, btw.

Anonymous said...

Python is very slow, and full of bugs; I mean, it compiles programs to pyc without a single warning; when one try to run the program, s/he gets garbage --- again, without a single warning; sometimes the same program runs correctly in one version, and produces garbage in another; garbage or correct values, everything is very slow. Besides this, Python does not have any of the modern productivity tools, like, type checking with type inference, pattern match, tail call optimization, etc. I am not fond of Haskell, but I recognize that (1) The compiler was written in Haskell, and has very few bugs; this means that Haskell is productive and safe; (2) Haskell is fast enough; I define fast enough when code runs from 3 to 2 times slower than C; for number crunch applications, Python is about 100 times slower than Common Lisp or Scheme, and 150 times slower than C (I used large wheather forecast programs to reach this conclusion); a program that runs in 8 minuter in Common Lisp takes two days and a half in Python, and 20 minutes in Haskell. (3) Haskell deals quite well with symbolic computation; this means that it runs from 3 to 5 times slower than Common Lisp; a genetic programming system in Python runs from 200 to 300 times slower than in Common Lisp.

Shannon -jj Behrens said...

I agree with everything except "full of bugs". Try coding ActionScript with the open source Flex SDK--that's what I call full of bugs! ;)

Python is what it is. I can still *think* in Python faster than in any other language. Perhaps it's lack of experience, but it generally takes me three times as much thinking to get the same amount of work done in Haskell. However, I still think Haskell is amazing.

By the way, have you read: http://jjinux.blogspot.com/2008/05/bipolar-lisp-programmer.html

Shannon -jj Behrens said...

BTW, anonymous, are you the guy who works at Choice Vendor?

Anonymous said...

Erlang is so simple that learning it can hardly count as much work - you'll probably need a week or so to learn the language thoroughly. Learning all the details of OTP takes slightly more work, of course, but that's not something you need immediately, so you can do that on the side. So there is really no reason why you shouldn't be able to do both, and apply whichever is most appropriate in the given situation.

Shannon -jj Behrens said...

> Erlang is so simple that learning it can hardly count as much work

I actually know Erlang at that level. I just don't know all the OTP stuff, and I'm not at the level where I could call myself an expert.

Anonymous said...

Try Rebol (http://www.rebol.com)

Anonymous said...

Unfortunately erlang is dog slow. If you don't want contribute to global warming, haskell or scala is the right choice ;)
hxxp://shootout.alioth.debian.org/u64q/performance.php?test=spectralnorm

Alex Wen said...

I would recommend Erlang. It's simple, dynamic typed. You don't need to declare enumerates. And it has so many libraries to use. From small to huge project you can use it.

Anonymous said...

You should think also to the number and the quality of libraries available in both the languages.