More WIP

With automaton fix (thanks @gavinking).

However, stack still doesn’t work. I suspect the typechecker isn’t
inferring type arguments across other type arguments (or something like
that), see comments in demo.