Channels ▼
RSS

Tools

In Praise of Haskell


"I've noticed several times when someone says ‘X really changed the way I think about programming,' frequently X=Haskell.”
— Andrew Binstock, editor-in-chief, Dr. Dobb's

The change in mindset Andrew is talking about has been experienced by many developers as they discover and apply Haskell, describing a true "aha” moment…a feeling that this is the way software development should be.

What Makes Haskell Different?

Haskell is a pure (actually, the purest) functional programming language. It has been in development for more than 20 years. Haskell programs are a series of high-level generalizable functions that define what the program is intended to do, and the language hides the mundane low-level details such as iteration. A strong static type-safety and inference system produces code with few side effects. The programmer focuses on results rather than articulating a lengthy series of steps. The compiler produces clean, concise, and correct code from the outset. If the code compiles, it works (almost all the time)! Contrast this with Ruby, for example, where the test code can be 2-3 times the size of the app, and even then, one is not quite sure if the runtime code is correct.

While it really shines in complex and unique analyses, Haskell can show its essential nature even in a simple snippet. Let's create a list of all even numbers up to 100, and another list omitting the first five of them.

The program written in Java The program written in Haskell

final int LIMIT=50;
int[] a = new int[LIMIT];
int[] b = new int[LIMIT - 5];
for (int i=0;i < LIMIT;i++) {
    a[i] = (i+1)*2;
    if (i >=5) b[i - 5] = a[i];
}

let a = [2,4..100]
let b = drop 5 a

It is immediately clear that with Haskell, you can understand what's going on; whereas in Java, or any imperative language, you can barely tell what the code is supposed to do because you are overwhelmed with the low-level minutia. This effect increases as programs grow more complex. From this simplicity and abstraction flow most of Haskell's advantages.

Because of these benefits, Haskell has an excellent reputation among developers who use the language. Comments from more than 3,000 Haskell programmers gathered by Hammer Principle indicate that Haskell is most liked for its type system; the confidence it creates that if the code compiles, then it is correct; and for the language's intrinsic elegance.

Improving the Economics of Software Development

While software drives the innovation economy, billions of dollars are wasted on project failures, bug fixes, and maintenance errors. Surveys and studies have consistently shown that 50%-75% of software projects are consumed by bug fixes and maintenance. One root cause of this problem is the use of current mainstream, imperative languages whose manual, low-level approach is error-prone and likely to generate spaghetti code when patched enough times.

This problem is well known but perpetuated because the vast majority of programmers, managers, and even journalists just believe "this is the way things always are." They try to improve around the edges with better testing tools, Agile, etc. But these aren't root solutions: They are workarounds. Poorly designed code in any language is a problem, but Haskell eliminates the spaghetti code via its type system, high-level syntax, and readability. Says one Haskell project leader, "We could revisit what we wrote in Haskell more than two years before and know exactly what was going on." This is difficult, if not infeasible, for most programs in Java, C++, Python, and other imperative languages.

Haskell's Sweet Spots

Algorithmic domains fit Haskell's algebraic and logical foundations well, as do problems that require parallel solutions. It is increasingly being adopted in enterprises, especially in data-intensive industries and domains such as financial services, big data applications, Big Pharma, and biotech, oil and gas, and consumer data.

Another important Haskell benefit is performance and its fast prototyping capabilities. The huge difference with other fast prototyping languages such as Ruby and Python is that a Haskell prototype can become the real app and stand the test of time due to its conciseness and correctness. A Ruby hack is easy to do, but gets you a lifetime of headaches down the road as you grow. For a startup, this accelerated time to market can be significant — especially in light of the reduction in repetitive testing and debugging.

The New York Times recently used Haskell to present Fashion Week, a processing-intensive app that used numerous images and required massive amounts of analysis. The lead developer on the project, Erik Hinton, wrote, "We chose Haskell because we anticipated doing a large amount of fine-tuning to get the analysis to work well." Compared with the Ruby prototype, the Haskell code with the Repa library ran 100X faster, in part because "the mathematical assurances made by Haskell's type system meant they could automatically parallelize the operation over multiple CPU-cores without changing a single line of code."

Consequently, if a high-level language that defines processing in terms of intended outcome, rather than through elaboration of individual operations; compiles to fast, native code; and is easy to parallelize fits your needs, I suggest Haskell might just be the language you're looking for.


Aaron Contorer is the CEO of FP Complete, a company that specializes in tools for Haskell developers. Earlier, he was at Microsoft, where he worked on the Visual Studio product and served as a technology adviser to Bill Gates.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video