Purity in Haskell

Despite having been buried under piles and piles of utter bullshit written by narcissistic idiots who are cosplaying self-proclaimed intelligence (the fate similar to that of the early Buddhism), Haskell has its true wonders, like any religion sect.

It is required for adepts to have a naive faith that doing things (performing rituals) in a particular way will eventually (but inevitably!) yield a salvation or at least liberation from suffering (and it does indeed!). Faith, by the way, is an naive, vastly oversimplified for a primitive packer's mind set of unquestionable beliefs which is a substitute for a complex, dynamic and relativistic view of actual reality. It is a good-enough "model of the world" to survive.

We want to believe that all the evaluation of our programs (expressions) is done strictly by re-writing of expressions (by applying this or that pre-defined reduction rule) while only substituting equal for equal - the way the expressions of pure logic have been evaluated by the first logicians of antiquity. We should believe (and then realize) that any functional program is a pure domain-specific logic (which is exactly what it is).

The abstract religious notion of keeping purity (of evaluation) and avoidance of a sin (of imperative side effects) has been used to firmly stick to the principles of equational semantics and evaluation by substitution (reduction) which allowed Haskell to remain a "pure formalized logic", similar to classic maths.

Also we have to believe that things do not change - whatever values has been created will stay unchanged until end of the time. This is rather beautiful, since there is no time in the first place, only unfolding processes, and processes (like a flame or a star) simply have no notion of the past (or future) - they are mere continuations (propagations) of itselves. Whatever has been done cannot be undone (changed) - this is a Universal Principle, indeed.

In principle, a Haskell program is a sequence of thunks (unevaluated closures) to be lazily (on-demand instead of in-place) evaluated by the runtime (by the Universe). The result of evaluation of a Haskell expression is not immediate actions to cause effects but rather a description for the runtime what must be done including which I/O actions (side effects) to perform. It is a protein (an enzyme) rather than a process. The runtime eventually runs the process.

This is exactly how Life itself (at the level of a single cell's molecular biology) works - there are thunks (RNAs) to be "evaluated" into corresponding proteins by the universe, and enzymes to be "executed" by it, etc, etc.

There is an explicit ordering of evaluation when needed with explicitly passing of an information (of a value) or without. (>>= and >> respectively).

This is absolutely wonderful application of a religious zeal to computer science. This self-sacrifice (by submitting to strict discipline) and arresting of "creativity" must be understood and even appreciated ^_^.

And indeed, under the hood a recursive desugaring and re-writing of expressions is all what the compiler does before generating the actual machine code (impure and sinful, indeed).

BTW, you might also like to read about Kundalini

Last modified 22 months ago Last modified on Apr 2, 2018, 3:43:35 AM
Note: See TracWiki for help on using the wiki.