jihoo.
3DGitHub ↗한국어
← Back to journal
JOURNAL / NOTES

Introducing ASL: What If Types Were Spaces?

Why would a language reject a function that swaps two points? An introduction to ASL, where types are finite topological spaces, and what that lets a program notice: gluing that fails, holes, and two spaces with the same numbers but different shapes.

ASL (Alexandrov Section Lambda) is a small pure functional language where types are finite topological spaces and functions between them are continuous. That sounds abstract, so this post goes through four programs, each a few lines long, and shows what the interpreter says about them. All the output below is from the Rust interpreter at commit b16c392.

The function that cannot swap two points

ASL’s built-in type S has two points, lo and hi, with lo < hi. A finite space in ASL is just a set of points with an order, and it carries the Alexandrov topology: an open set that contains a point also contains everything above it. With that topology, continuity is the same as preserving the order. If x ≤ y, then f(x) ≤ f(y).

That leaves exactly three functions of type S -> S: always return lo, always return hi, or return the input. You can still write down a table that swaps the two points:

let swap = tab S -> S { lo => S.hi, hi => S.lo };

The interpreter rejects it, and says which pair of points the table breaks:

<stdin>:1:12: nonmonotone map: S.lo <= S.hi, but S.hi is not <= S.lo

In most languages a type is a set of values. In ASL it is a set of values and how they relate, and a function has to respect both.

When the pieces work but the whole does not

You can define a function one small open piece at a time and join the pieces with sew. In ASL the small pieces are stars: Star(X, p) is the point p together with everything above it. Here a space has two points, west and east, both below a seam:

space Joint { west < seam, east < seam };
let w = tab Star(Joint, west) -> S { west => S.lo, seam => S.hi };
let e = \x : Star(Joint, east) => S.hi;
let lamp = sew Joint -> S { west => w, east => e };
show lamp(Joint.seam);   // S.hi

For sew to succeed, the stars have to cover the whole space, and wherever two of them overlap, the pieces have to agree. Here they overlap only at seam, where both say S.hi, so there is exactly one continuous function that restricts to both pieces.

The interesting case is when every piece is fine on its own and the gluing still fails. The double-cover example tries to choose a “sheet” of a two-sheeted cover on each vertex star of a triangle. Two of the overlaps force the choices, and when you get all the way round, the last overlap disagrees:

examples/rejected/double-cover.asl:23:62: overlap conflict at Circle.ca: chart 'a' gives Cover.ca1, chart 'c' gives Cover.ca0

Starting on the other sheet only swaps the two answers. No choice works, because the cover twists once around the loop. That is the gap between locally possible and globally possible, and here it shows up as an error at a line and column.

Counting holes

betti computes Betti numbers, which count holes in each dimension. The triangle example builds a circle as the boundary of a triangle, rotates it one step by gluing three local maps, and asks a few questions:

betti(Circle) = [1, 1]
betti(Circle * Circle) = [1, 2, 1]
homotopy = no

The circle has one piece and one loop. Its product with itself, a torus, has two independent loops and one two-dimensional class. The last line asks whether the rotation can be deformed into the identity inside the finite function space. It can’t, because each step there has to move all outputs in the same direction at once.

Same numbers, different spaces

Betti numbers don’t tell spaces apart on their own. The real projective plane and the wedge of a circle and a 2-sphere both come out as [1, 1, 1]. Each has exactly one nonzero class in degree one. ASL has a type for that: H(X, k) is the space of degree-k cohomology classes of X with coefficients mod two. So you can write a function that takes the class and squares it:

let squareRP = \u : H(RP2, 1) => cup(u, u);
let squareWedge = \u : H(Wedge, 1) => cup(u, u);
show squareRP(gen[RP2, 1, 0]);       // H(RP2, 2){g0}
show squareWedge(gen[Wedge, 1, 0]);  // H(Wedge, 2){0}

On the projective plane, the square is the nonzero class in degree two. On the wedge, it is zero: the degree-one class comes from the circle, which has nothing in degree two. Same numbers, different multiplication, so the two spaces are not the same.

The same program goes one step further. After suspending both spaces, every cup product vanishes, so squaring can’t tell them apart any more, but the Steenrod square Sq¹ still can. It also applies Sq¹ to the millionfold suspension of the projective plane and gets a nonzero class in degree 1,000,002, without building a space that large.

Where it has gone since

When I first wrote this post, the interpreter could do the first three sections. Since then ASL has grown well past them. The README now covers Massey products, Adams E₂ pages and the algebraic May spectral sequence, among other things. One example: the classifying spaces of the cyclic groups of orders 4 and 4,096 have isomorphic mod-two cohomology rings, and ASL tells them apart by how many copies of the degree-one generator it takes to get a nonzero Massey product.

That part deserves more than a paragraph. The thing I wanted to show here is the starting point: once types carry an order, ordinary functions can already notice things like twisting, holes and the shape of a ring.

Try it

From a clone of the repository, with Nix:

nix run path:. -- examples/descent.asl
nix run path:. -- examples/projective-plane.asl

Or with Cargo, including a one-line program from standard input:

cargo run --offline -- examples/projective-plane.asl
printf '%s\n' 'show (\x : S => x)(S.hi);' | cargo run --quiet --offline -- -

The interpreter uses only the Rust standard library. Computations are finite, but the number of functions between spaces grows quickly as you add points, so the examples stay small.

← All notes