Sam Gentle.com

A Null of Nulls

In some programming languages, not least of which my personal albatross of Javascript, there is a concept of a Null. Null is fascinating because it's kind of an un-value, it's not "yes", not "no", but more like "I disagree with your question". If someone asks "Have you stopped beating your wife yet?", the only correct answer is Null. Buddhism has the concept of Mu, which is a similar philosophical un-value.

But we can't stop at one Null - not at all! Because the problem is, once you have a Null, you can ask questions to which the actual answer is Null. An example: imagine a function, first, which returns the first element in a list, or Null if there is no first element. So if you pass first an empty list, you will get Null. But what if you pass it a list containing exactly one element: a Null?

Not to worry, because Javascript has undefined! So if you ask for the first element of an empty list in javascript, you get undefined. And if you ask for the first element of a list whose first element is undefined? Then you still get undefined. Oops.

One answer to this is Exceptions, which are the equivalent of when someone asks if you've stopped beating your wife, saying "don't ask me that" and bailing out of the conversation entirely. Probably a sensible response! But this is a fairly brittle approach, because your conversations can change flow unpredictably and you have to be aware of every kind of question that you can't answer.

But I think the most elegant answer of all comes from functional programming. Instead of having Nulls, they have a special Maybe value. Maybe is a way of explicitly saying "I will give you an answer, or a not-an-answer". So a Maybe Boolean is either Just True, Just False, or Nothing. So it's not meaningful to say "answer yes or no: have you stopped beating your wife?", but you could say "Maybe answer yes or no: have you stopped beating your wife?"

Why is this better? Well, unlike Javascript's ugly null and undefined values, you can have a Maybe of a Maybe. The answer to "what is the first element of an empty list?" is Nothing. The answer to "what is the first element of a list which only contains Nothing?" is Just Nothing. If you put that in a list and get the first element, it's Just Just Nothing. And so on. There's an infinite tower of Nulls, each un-answering more than the last.

I wonder if eastern philosophy has any notion of a meta-Mu?