-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we derive function extensionality from self types only? #12
Comments
I think this is relevant (UIP):
Note this only holds if we allow the erasure of functions (i.e., accept |
I don't believe this is true. Intervals have no more than 1 equality between two values, and there have been systems with quotient types and UIP iirc. Of note: the standard proof of funext from the existence of an interval requires that you have eta-equivalence (i.e. f = \x -> f x definitionally) in addition to definitional pattern matching on the interval. That said I think it's not easy to answer one way or another easily without proper consistency, but pretending that it was consistent, you most likely you cannot prove function extensionality as it implies the existence of non-canonical identity proofs (that is, closed terms of type |
@MaiaVictor Here is my proof that given @jasoncarr0 It's true that the usual That said, your comment about non-canonical identity proofs is exactly in line with my thinking as to why we won't actually be able to instantiate |
The difference here is UIP/K is an internal statement, whereas canonicity is an external statement. Here since you have UIP you could still prove propositional equality of any proofs of equality. I don't know that you'll get any farther with that eta-expanded funext form. |
We have internal proofs of UIP/K with erased
Non-erased
However, I think an external statement of canonicity would follow from noticing that if
which, unless you break consistency, has to be structurally equal after erasure to |
@johnchandlerburnham Ah I think I misread your comment a bit. Thanks for the great write-up |
@MaiaVictor The linked gist https://gist.github.com/MaiaVictor/28e3332c19fbd80747a0dceb33896b6b now type errors on latest formality-core with
|
Having investigated this, the issue is caused by the removal of an experimental typechecking feature that allowed an application of an erased lambda to equal its argument: So you have to use
|
The main insight behind self types is easy to explain. Simple functions can be written as
A -> B
, and an applicationf
a has typeB
. Dependent functions can be written as(x: A) -> B x
, and an applicationf
a has typeB a
. The insight is that the type returned by an application has access to the value of the argument a. Self dependent functions can be written ass(x: A) -> B s x
, and an applicationf a
has typeB f a
. The insight is that the type returned by an application can also access the value of the functionf
! This simple, elegant extension allow us to construct inductive datatypes with lambdas.It is not rare for generalisations to allow us to do things beyond the concrete reasons they were discovered. So, a question is, what else self-types allow us to do? A very interesting thing we just found is the concept of smart-constructors, i.e., constructors that compute. With them, we can define an Int type as a pair of Nat such that the constructor itself canonicalizes its values, i.e.,
(4,2)
becomes(2,0)
,(3,5)
becomes(0,2)
, etc. We can then trivially prove that(a,b) == (succ(a), succ(b))
. This is as elegant as the quotiented formalization, without the computational blowup.What would be really great is an implementation of intervals, i.e., a type inhabited by two definitionally equal values,
i0
andi1
such thati0 == i1
. We've got surprisingly close by adding a phantom constructorie : i0 == i1
to the self encoding. It works as expected: to eliminate an interval, one must provide a proof that both returned values are equal. But there is one thing missing: the construction ie itself, left as an axiom. If we managed to construct it, then Funext would follow trivially. Even if we don't, this might point to a simple primitive that could allow us to have it without needing to addi0
andi1
as native concepts.If anyone is willing to try, I've made this self-sufficient Formality-Core file:
Formality-Core is just an implementation of a dependently typed language with self types, a fast type checker and nice error messages. Running it is extremely easy (5 commands in a Linux environment), so give it a try! If you have any reason to suspect this is either possible or not, or any pointers to how we could change the language as slightly as possible to complete this proof, we'd be thrilled to know.
Note: you need to use [email protected] since it considered the application of an erased
f
tof(x)
equal tox
. We don't do that anymore (erasures don't affect type-checking at all and may even be removed from core soon).The text was updated successfully, but these errors were encountered: