For the past month, I have been working on Pterodactyl’s definitional mechanism, by which I mean that way that you make top-level definitions in the system. As I said from the start, I want to support Epigram-style definitions with pattern-matched left-hand-sides. I made several false starts and I finally arrived at something that works, but this too is not quite what I will need.
What I currently have is the ability to write definitions like the following example of the “type theoretic principle of non-choice”, i.e. the distributivity of products over sums:
nonChoice
(I : Type) (A : I -> Type) (B : (i : _) -> A i -> Type)
(h : (i : _) -> record {pi1 : A i; pi2 : B _ pi1})
: record {pi1 : (i : _) -> A i; pi2 : (i : I) -> B _ (pi1 i)}
where
nonChoice I A B (\_ => {f; g}) => {_; g}The above illustrates how the pattern variables in left-hand side of the clause above are resolved using higher-order dynamic nested pattern unification. It took an immense amount of work to get this set up, because the unification algorithm is brand new (due to András Kovács) and very intricate. The example above exercises the machinery quite a lot: in addition to supporting a deep match underneath a binder on the left (this is the nested part of nested pattern unification), the underscores in non-pattern positions are placeholder that are filled in by the unifier as well.
All that is very good and exciting. Where I have gone wrong is in how I create the environment against which the right-hand side is elaborate. My thinking was that I would want a “clean” environment in the pattern metas on the left become the local variables on the right; this is what I, at long last, have managed to implement. Unfortunately, that is not adequate for what will come next (the introduction of Epigram-style eliminator refinement). For that, it will be important to not wholesale replace the ambient environment, but rather to simply rename and possibly extend it.
There is a trade-off: when we do nested patterns on the left, we may bind pattern metavariables in such a way that the resulting names do not lead (even up to \beta {}/\eta -equivalence) a complete renaming of the local variables. For example, in the example above, the destination of the ambient variable h is not another variable, but a nested pattern that names two additional variables f,g which are solved as f := \i => h i .pi1 and g := \i => h i .pi2.
The “benefit” of my existing approach is that I get a totally clean new local context that doesn’t mention h at all and simply takes f,g as the primitive local variables. Unfortunately, I believe I will have to go for a middle ground where I instead keep the local context, rename whatever can be renamed directly, and then add new local definitional bindings for things like f,g. This means that the goal may still mention old ambient local variables (which will now be in scope). In return for this, I will be able to deal with the hidden hypotheses that are not mentioned in the program/goal label (lhs), including things like induction hypotheses.
Anyway, this past few weeks has been an example of stepping on the diagonal: we are making forward progress, but somewhat slewed.