I’ve been dealing with concurrency for many years in the context of C++ and D (see my presentation about Software Transactional Memory in D). I worked for a startup, Corensic, that made an ingenious tool called Jinx for detecting data races using a lightweight hypervisor. I recorded a series of screencasts teaching concurrency to C++ programmers. If you follow these screencasts you might realize that I was strongly favoring functional approach to concurrency, promoting immutability and pure functions. I even showed how non-functional looking code leads to data races that could be detected by (now defunct) Jinx. Essentially I was teaching C++ programmers how to imitate Haskell.
Except that C++ could only support a small subset of Haskell functionality and provide no guarantees against even the most common concurrency errors.
It’s unfortunate that most programmers haven’t seen what Haskell can do with concurrency. There is a natural barrier to learning a new language, especially one that has the reputation of being mind boggling. A lot of people are turned off simply by unfamiliar syntax. They can’t get over the fact that in Haskell a function call uses no parentheses or commas. What in C++ looks like
f(x, y)
in Haskell is written as:
f x y
Other people dread the word “monad,” which in Haskell is essentially a tool for embedding imperative code inside functional code.
Why is Haskell syntax the way it is? Couldn’t it have been more C- or Java- like? Well, look no farther than Scala. Because of Java-like syntax the most basic functional trick, currying a function, requires a Scala programmer to anticipate this possibility in the function definition (using special syntax: multiple pairs of parentheses). If you have no access to the source code for a function, you can’t curry it (at least not without even more syntactic gymnastics).
If you managed to wade through this post so far, you are probably not faint of heart and you will accept the challenge of reading an excellent article by Simon Peyton Jones, Beautiful Concurrency that does a great job of explaining to the uninitiated Haskell’s beautiful approach to concurrency. It’s not a new article, but it has been adapted to the new format of the School of Haskell by Yours Truly, which means you’ll be able to run code examples embedded in it. If you feel adventurous, you might even edit them and see how the results change.
April 4, 2013 at 11:07 pm
What is this “t” in the tutorial (as in IO t)? Is it a predefined contant, or a placeholder for a variable (a pattern in Mathematica-speak), or is “IO t” just a single token, or is it something else entirely?
April 5, 2013 at 8:58 am
Bart, I don’t think most programmers are put off by Haskell’s syntax. I think what makes Haskell unapproachable is what’s considered intermediate to advanced Haskell abstractions. Personally, I have learned through what’s covered in Real world Haskell, enjoyed it a lot, and wrote several thousand lines of codes for personal projects and scripts in it. I was however put off by the more advanced concepts such as Arrows, FRP, RankNTypes, and zillions of GHC extensions. Although in theory it’s true that you can take a small subset of the language and avoid the unfathomable parts, in practice that is not going to happen. You need to interact with a community of mostly academics with penchant for creating and using these advanced type theoretic constructs even in the simplest situations. Code samples from haskell cafe looked almost like gibberish to me even though I was actively writing Haskell code on a daily basis. Note that I would have loved to learn the guru-grade constructs, unfortunately other than academic papers, no other introductory material existed (and to my knowledge that is the case today). I felt in a way like when I was a noob C++ programmer, trying to read template meta programming code. There were at least some excellent material on the latter topic.
April 9, 2013 at 6:46 pm
@TJR: t is a type variable. IO is a parameterized type, like a template in C++. In C++ it would be IO. In this case it stands for the type returned by the IO action.
April 9, 2013 at 7:03 pm
@Ali Razavi: You’re right about the academic section of the Haskell community that enjoys talking about advanced ideas using highly abstract language. We would like to encourage people to write accessible tutorials about these topics in the School of Haskell. It’s a very young web site– we’ll see what the future will bring. We’re planning on making it more interactive, so readers will be able to post comments and evaluate content.
April 19, 2013 at 2:42 pm
Bartosz I see 2 problems with you convincing ppl to learn Haskell: 1) ppl dont get some stuff about FP-for example my last Q in your previous blog post
2) you are not presenting Haskell as solution in a convincing way… aka give us an example of realistic real world crappy Java/ C#/ C++ app that is crappy because of language limitations not because coder is bad, re implement it in Haskell and that is it. But again please dont make unrealistic application in a sense that it is useless and in a sense that is intentionally badly written in imperative lang.
April 20, 2013 at 10:10 am
@nonsenseetal: Every time there is a paradigm shift, some people don’t get the new paradigm. I remember the same was said about object oriented programming. Time will show.
As for real-world examples, probably the biggest client of Haskell is the financial industry, and they don’t speak about it too much in public. You might have a look at a discussion on Hacker News about an open source trading system written partially in Haskell. Notice that there is pretty much a consensus that Haskell is the right language for concurrency. We have also published several case studies of successful companies using Haskell.
April 21, 2013 at 11:42 am
@Bartosz
well i think that consensus is not from the unbiased sample of developers.. 😀
BTW if you find time I would really like to know A to those 2 Q I posted in a comment on your previous post.
I saw the case studies when they came out, iirc there was only a few then, now I see more so Ill recheck them…
P.S. If I sound antagonistic it is not true… on todo learn lang list Haskell is my #1, that is why I said in my previous comment that I would really enjoy Coursera Haskell course, but a semi-serious one (10+ weeks) of material not intro.
P.P.S. regarding financial industry… if you are for some data mining you could mine:P job offers for financial sector and see how ofter Haskell is mentioned and use that to explain to ppl how they should learn Haskell for a greater good and profit. 😀