Empty List
[]
(which represents emptiness) acts like an identity element for an
operation that chooses between alternatives, when a List
of possible
choices is returned. This is a common, standard idiom.
Empty is not an “error” or a “failure”, but a signal to stop, prune, backtrack and delete the empty, now cyclic path.
Considered as an identity element for an operation of a choice between
alternatives: if [] then try the next one
.
This is a standard idiom in parsing - the current parser sees nothing (returns an empty result) - try the next one.
This is idiom is applicable for an ordinary Monadic composition, or for composition of partial (non-total) functions.
This generalizes the pattern of selection in the process of systematic exploration or a complete traversal of a tree-like (acyclic) structure.
This is at the core of universal backtracking search, which either abandons the path on a contradiction or a dead-end or an expected base-case.
Such kind of a search is complete.
A recursive traversal with stops at an expected base case ([]
) is also a
special case of a backtracking search process.
[]
(but not null
) is a legitimate signal and is an identity for
concatenation.
so is the ""
(the empty string).
Again, being an identity element for concatenation operation is what
makes them leigitimate. A general NULL
is not an identity and is a
huge and embarrassing theoretical mistake (by math-illiterates).
Maybe
is just this empty/non-empty (Nothing or Something) aspect of a
list
being redefined with a different pair of constructors.
A recursive traversal of a tree stops (and recursion backtracks)
at every expected Leaf
.