At QTCat, @pigworker gave (remotely) a talk about type theory which was very tho...
AmΓ©lia Liao π @amy@types.pl
At QTCat, @pigworker gave (remotely) a talk about type theory which was very thought provoking to us in the implementation mines. There was something about record types with a 'floating' field keyword, which I guess I won't be emailing her about (but on which I have thoughts to share that need a bit more baking), but there was also an offhand comment about boundary-sensitive elaboration, something whose absence in Mikan I have made my peace with. I will now yap about it.
There's a sort-of bad reason for us not doing it, but there's also a reason I believe has merit. The bad reason is that, among us experts, one will find no clues, not even a single one, on how to algorithmically elaborate higher pattern matching to eliminators; so when checking a function definition with higher clauses, Mikan doesn't know what the boundaries of those clauses are until after we've done termination checking, which is way after the term elaborator is done. I don't have hard numbers but I'm actually pretty sure that most boundary constraints when working in Mikan come from these clauses. But, like, alright, this is a deficiency of the implementation, and if we had an algorithm for elaborating higher pattern matching (which would give us Path types for these clauses), it would go away.
The other reason for not doing it, the one that I believe has a bit more merit, is that the judgemental structure of type theory prevents boundary sensitivity from actually being that useful. The 'judgement' Mikan uses to elaborate path abstractions looks like this, if you'll let me pay off my Unicode by not having gammas:
i : π β’ e β A
e[i0] = x
e[i1] = y
----------------------
(Ξ» i β e) β Path A x y
That is, to check a path abstraction, we check the body, then impose two equational constraints on it by conversion checking. If the body of the path is a metavariable, we now have two unsolved equational constraints on that meta, since the intervals' endpoints in its spine knocks them out of the pattern fragment. A better idea is to have a judgement like
Ξ β’ e β A [ Ο β¦ v ]
where an expression is elaborated not only against a type but against an expected (partial) value, its boundary. We can then tell the body of the path what boundary it must conform to, and, if that body happens to be a meta, we can tell the user not only what type they must construct but also what faces their value should have. Great if we don't want them to cube blind.
i : I β’ e β A [ (i = i0) β¦ x ; (i = i1) β¦ y ]
---------------------------------------------
(Ξ» i β e) β Path A x y
It would be really nice if the terms into which we can push boundaries are exactly the checking terms. This is not the case. We can push boundaries into introduction forms for negative types with eta equality:
a β A [ Ο β¦ v .fst ]
b β B a [ Ο β¦ v .snd ]
----------------------
(a , b) β Ξ£ A B [ Ο β¦ v ]
x : A β’ e β B x [ Ο β¦ f x ]
---------------------------
(Ξ» x β e) β Ξ A B [ Ο β¦ f ]
And we can even push boundaries into stable constructors of inductive types, where here stable means, approximately, that the constructor is not a higher constructor applied to a variable mentioned in the face formula Ο, as long as we're willing to impose an equational constraint on the boundary:
x β A [ Ο β¦ hd ]
xs β List A [ Ο β¦ tl ]
v = hd β· tl
---------------------------
(x β· xs) β List A [ Ο β¦ v ]
This rule is sufficiently different from the others that I feel iffy about it. For eta-things, we can just move the elimination opposite the term's position into the boundary, but here we have to take the boundary apart to know what goes where. For higher constructors, the situation is... worse. If we have a problem
(squash ?0 ?1 i) β β₯ A β₯ [ (i = i0) β¦ x ; (i = i1) β¦ y ]
You might imagine that since squash ?0 ?1 i is unstable with boundary [ (i = i0) β ?0 ; (i = i1) β ?1 ], we could elaborate ?0 β β₯ A β₯ [ i1 β¦ x ], which completely determines the meta, leaving two solved goals! But that's not actually true, since we could also solve ?0 := squash x y i, and our overall term would still have the right boundary. The correct elaboration subproblem is ?0 β β₯ A β₯ [ (i = i0) β¦ x ], which is still undetermined. (A drink in, I might call this "the fundamental problem of unification under boundaries").
Moreover, here, I used my human understanding of the problem to push the boundary into the arguments manually. I have no idea how to derive an algorithm for doing this from the type of a higher constructor! This is a situation where you have to use the "cry about it" judgement:
e β A
Ο β’ e = v
--------------- [π]
e β A [ Ο β¦ v ]
This is like the mode-switch judgement for checking a form that wants to infer, but here we can preserve the expected type and only give up on the boundary. Indeed, if we're checking an inferring form, the mode-switch judgement will factor through crying about the boundary. This means that we can push boundaries to metavariables, but:
- If, between picking up the boundary and running into the metavariable, we had to stop by a higher constructor (still a checking form!) or a function application, we'll have lost the boundary, and we're back to blindfolded higher cubing. How do users fill cubes? With higher constructors, where we might be able to push boundaries into arguments, or with functions into paths (like an assumption of truncatedness), where there is no hope.
- Even if the higher constructor is particularly nice, or particularly hardcoded, like the
squashof a truncation might be, propagating the boundary into metavariables does not actually determine the metavariables, and you still have to write out the solution. This means you still wouldn't be able to writesquash _ _ ito score a goal-with-boundary.
Mikan does not do any amount of boundary-sensitive elaboration. However, she can still tell you, in some situations, what faces a metavariable should have! I taught her to identify when an equational constraint on a metavariable, pushed down by the ordinary conversion checker, is the shadow of a "boundaried" judgement: it's almost in the pattern fragments, but you also have some endpoints in the spine. Since the conversion checker knows about eta, and about definitional injectivity, and about reduction, we get both the happy, confusing and depressing cases of boundary-sensitive unification for free.