Monday, February 12, 2007

Haskell for Alphas and Betas

A few times now I've seen or heard an argument that goes like this:
Haskell is fine for people with the Hacker Nature, but there is no way that the average Code Monkey is ever going to grok recursion, let alone monads. Therefore Haskell is doomed for use in the Real World, and will forever remain a plaything of academics and over-enthusiastic start-up companies.
Lets call the people who can define new monads "Alphas" and the rest of the developers "Betas". First of all, its worth noting that most, if not all the people who make this assertion are in fact Alphas, and they might be surprised at how much some other people can understand. But I can accept that there are people out there who generate software, but for whom software is not a primary skill. For example a physicist who writes a numerical simulation of particle interaction in Fortran, or a financial trader who's understanding of how to price a swaption is embedded in Excel. And of course the favourite example: people who's primary job is the design of dynamic web applications and who know just enough to query a SQL database and convert the results into HTML. Some of these people are capable of groking the monad laws, but they are not interested in theoretical computer science. So how will they do in Haskell?

I think a clue comes from an experience report on Eiffel. The application was for financial derivatives back in the 90s. The developers used Eiffel to create a library of classes (which would now be called an embedded domain specific language) for derivative construction. It sounds not unlike the one proposed by Simon Peyton Jones in Haskell. Once the developers had generated a library of Eiffel classes, the people who understood derivatives could use the existing library to describe esoteric financial contracts and define the pricing algorithms associated with them.

This is the way that Haskell should go in the future. The Alphas can formalise the problem domain in a way that saves the Betas from having to understand any advanced stuff like GUIs, database access, and all the other stuff that makes our lives so interesting.

Excel is very much a case in point here. It has been called "the most popular functional programming language in the world", although of course it is not Turing Complete. But it shows that many people can get their heads around a system of linked equations, and even simple recursion where necessary.

But the real beauty of Haskell is that it doesn't have any built-in concept of flow of control. This may sound like an odd advantage, but it allows an embedded DSL to have a monad embodying its own domain-specific notion of control flow in which the cause-and-effect model follows the model of the domain experts rather than the rest of the language. Parsec (the recursive descent parser library for Haskell) is a good example: a parsing action can have side effects, but anything that happened in a failed parse is guaranteed to be invisible. Coming up with Parsec took some Alpha brains, but now any Beta can write a parser in Haskell without worrying about the interaction of side effects and backtracking.

Environments such as Vital may help to push this even further by providing an intuitive spreadsheet-like front end, but many of the Betas don't actually need it: they are happy with expressing their knowledge in source code; they just want a language that thinks the same way they do.

So I really don't think that Haskell has to be a closed world to the Betas. The Alphas will interpret the domain as a library of monad combinators, and the Betas can just use the library without worrying about details like the exact flow of control. Over time some of the Betas will come to understand and be promoted to Alphas, and the rest will continue to code unabated.


Adam said...

Perfect. Can you mention this to Karsten Wagner?

Tony Morris said...

Perfect. Can you mention this to Karsten Wagner?

I just spat my lunch all over my keyboard in laughter!

Karsten Wagner said...

Can you point out what's so obviously wrong in my articles, after you cleared your keyboard?

The problem with DSLs is the high abuse potential:

To many 'Betas' think of them self as 'Alphas' and mess with things they shouldn't mess with. But also to many 'Alphas' create new DSLs because they need some tiny extension to a existing DSL which does nearly the same - and often only just because they are so 'alpha' (this is also called the "not invented here-syndrome").

Both are a quite obvious problems in Java-land, where more and more frameworks (which are also DSLs, especially if combined with reflection and code-generation) mess the whole thing up. Do you really want this in other languages too?

One way to prevent this is to make the entry level for creating a new DSL high enough so that it's only done where absolutely necessary (because the betas won't reach this level and the alphas are to lazy).

But if a language misses a really important abstraction, it's often better to build it directly into the language itself:

The 'betas' won't even think about creating a DSL if the language itself is already powerful enough. And the 'alphas' have already submitted under the language itself, so they don't feel to be 'betaized' if they use a DSL of another developer.

Thomas David Baker said...

My boss says Excel IS Turing Complete.

Can you elaborate a bit on why you think it isn't?


Anonymous said...

When the Wow Gold wolf finally found the Buy Wow Goldhole in the chimney he crawled wow gold cheap down and KERSPLASH right into that kettle of water and that was cheapest wow gold the end of his troubles with the big bad wolf.

game4power,buy cheap wow goldWOW GOLDThe next day the cheap wow gold buy gold wow little pig invited his mother over . She said "You see it is just as I told you. The way to wow goldget along in the world is to do world of warcraft gold things as well as you can." Fortunately for that little pig, he cheapest wow gold learned that lesson. And he just lived happily ever after!