What is Haskell’s primary feature?

Today I was asked what Haskell’s main feature is. The answer is its non-strict evaluation.

Java is a strictly evaluated language. Consider this Java program:

class C {
  static String i() {
    throw new Error("boo!");
  }
 
  static <A> int f(A a) {
    return 3;
  }
 
  public static void main(String[] args) {
    int k = f(i());
    System.out.println(k);
  }
}

The program fails with a runtime error.

Consider this (otherwise equivalent) Haskell program:

i = error "boo!"
 
f a = 3
 
main = let k = f i
       in print k

The program prints 3 and does not fail like the Java program. This is a key property of Haskell with very far reaching implications. One of those implications is that Haskell is a pure language. There are many more implications, particularly with respect to the compositional properties of programs.

Haskell’s evaluation model and its implications is perhaps its most widely misunderstood feature. While the benefits are (enormously) enormous, they are far too deep to consider writing a short article about.

One Response to “What is Haskell’s primary feature?”

  1. Thomas Wood Says:

    Some aspects of this quite frankly shocked me, when shown by a PhD student in a lecture, I’m still having trouble figuring out exactly how it managed to work!

    I still love the simplicity of the Fibonacci number generator that relies on this principle:
    fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

Leave a Reply