The Dongola Times

(Anachronistic) Dispatches from the Kingdom of Makuria.
16th of June, 2013

Wild Haskell Analogies #2: The Leap of Faith

In the Haskell programming language, there is no move that can go wrong. The language is well-typed, and one of the sages who designed it once said: “well-typed programs cannot be blamed.” He was correct; these Hebrews don’t just make empty pronouncements. Haskell is like a society that lives by pure reason. (Therefore cue Kant and his ponderous critique.) Such a society cannot be blamed; for everything is validated by the light of reason.

Yet there is an opposite (and more-ancient) Worldview, which is that of faith. And I am of the side of faith, so I will be slightly biased. In the days of blind faith, which we now call dark superstition, the society got guidance from its mystics, and when the mystics turned out to be wrong, as they often did, the people grew impatient with faith, and opted for reason.

The linked list is the primary data structure in Haskell. Purely-functional programming goes phallus-in-vag with the linked list. They are co-designed for each other, by their nature, and it would be a major misrepresentation to say “hand-in-glove” or “sword-in-scabbard”. It has to be phallic symbolism, because it is that great.

The problem with the linked list—and therefore with functional programming—is that it cannot do faith. Faith involves a leap of some sort. The 70,000 fathoms of Kierkegaard routinely show up in computer programs as “random access”. For that, we use the array. Just as with the ancient faiths, and the modern distaste for faith-things, we were routinely let down by our faith. The disappointment of those who trusted in the unseen is very similar to the famous java.lang.ArrayOutOfBoundsException. Sometimes, a C program takes a leap of faith hoping to find that its god—the programmer—has kept the promise and covered all the bases. And because we are imperfect, there is every now and then a case of … Segmentation fault.

Haskell fixes this by not relying on faith at all. There is no random access. Haskell is the most-rigourous achievement of a World devoid of faith in the unseen. It makes Baconian science a dark and superstitious cult by comparison. Yet Haskell still needs to take a leap of faith, and it is very interesting to see when it does. Since it has no trust for input-output, it cordons off everything that has touched foreign data. The neat observation is that array access, in Haskell, is itself a case of input-output. Why? Because random access will always be analogous to prayer (input-output); using an array will always be an analogy of having faith. The input of IO will always be an analogy of inspiration or a message from God. It could introduce unpredictable behaviour in the program (for Haskell is purely materialistic, purely predictable, purely rational, purely logical, purely-functional, until IO is introduced). But in times of stress for the program, when we do not know what to do next, there is always the option of prayer—input-output—and it may come with a heavy price (“exit”, for example, or a consequent crash, the possibility of which is only ever introduced by IO in the Haskell world), but at least we know what to do next. Take a leap of faith.