JUNK: a programming notation

JUNK is an algebraic programming notation which uses quantales as a primary organising principle, both for data and for code. Quantale modules also play a role, as well as monads; dictionaries are treated in such a way that they behave both very much like other values and very much like other functions.

We start with brief overview of the mathematical preliminaries, and proceed through a tour of the data values, both eager and lazy; the functions, and their application to values; and finish with a sampling of some advanced features made possible by the core theory, followed by some algebraic highlights of the theory.

0. Mathematical Preliminaries

A unital quantale is a monoid in the category Sup of complete join-semilattices. On this page we use ASCII: we spell multiplication as comma `,` with identity `Nil`; spell the join as pipe `|` with bottom `Null`, top `Nuts`; and natural order as `~` (`x ~ y` equivales `x|y == y`). Multiplications distribute over joins, and here they are noncommutative. We will refer to multiplication-prime elements (the alphabet of the monoid) as "items", and refer to join-prime elements as "atoms".

For a quantale Q, a left Q-module is a sup-lattice M together with an action `(Q,M)→M`, satisfying the usual axioms; a right Q-module has action `(M,Q)→M`.

1. Data

There are three sorts of data values:

User-defined algebraic datatypes also count as complex, and we can view `[]` and `{}` as being similar to other constructors, except with special mixfix syntactic representation.

The join of two items is an item, and `|` distributes across `[]`, so `[0|1]` = `[0]|[1]` which is an item but not an atom. Note that `|` does not distribute across `{}`; `{0|1}` is distinct from `{0}|{1}`.

2. Strictness

There is another simple datum: `NotYet` which is part of an ordering `:~` in which it lies below all other values, all of which are indiscretely related by `:~`. As the name implies, `NotYet` serves as a lazy placeholder for a datum which will be better approximated, later, by a stricter value.

JUNK’s order is lexicographic (:~,~), ie strictness first, joins second, but in implementation it collapses to a flat-lattice.

3. Functions

Similarly to data, there are three types of function:

        (f|g)(x) == f(x)|g(x)
        (f,g)(x) == g(f(x))

4. Principles of Application

Application is join-preserving: `f(x|y) == f(x)|f(y)`. Furthermore, application of a function to a value outside its domain results in `Nuts`. Application is monotonic in `:~`, the ordering containing `NotYet`. Functions are naturally ordered, `f~g` is equivalent to `(f|g) == g`.

5. Advanced Features

Note that because `$$` and `$?` are useful for analysing complex expressions and patterns into simpler subexpressions and subpatterns, they induce a straightforward translation into ANF.

6. Algebraic Highlights

Influences

Shout outs to Backus, Burstall, Conway, Dijkstra, Hehner, Iverson, Kleene, McCarthy, Scott, and Wadler.