Skip to content
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

Allow flat matching on inductive families #6238

Closed
felixwellen opened this issue Oct 26, 2022 · 4 comments
Closed

Allow flat matching on inductive families #6238

felixwellen opened this issue Oct 26, 2022 · 4 comments
Assignees
Labels
cubical Cubical Agda paraphernalia: Paths, Glue, partial elements, hcomp, transp documented-in-changelog Issues already documented in the CHANGELOG flat The @flat/@♭ modality modalities regression on master Unreleased regression in development version (Change to "regression in ..." should it be released!)
Milestone

Comments

@felixwellen
Copy link
Contributor

The following example does not type check with latest Agda (master):

{-# OPTIONS --cubical #-}
open import Agda.Primitive

data Flat (@♭ A : Set) : Set where
    flat : (@♭ a : A)  Flat A

data Id {A : Set} : A  A  Set where
  refl : {x : A}  Id x x

CommFlatId : {@♭ A : Set} {@♭ u v : A}  Flat (Id u v)  Id (flat u) (flat v)
CommFlatId (flat refl) = refl

Agda gives the following error:

/home/felixcherubini/repos/test.agda:11,1-30
Agda.Primitive.Cubical.primTransp
(λ i →
   Id (flat u)
   (flat
    (Agda.Primitive.Cubical.primTransp
     (λ i₁ → Agda.Primitive.Cubical.PathP (λ i₂ → A) (x i₁) u) φ x₁
     (Agda.Primitive.Cubical.primINeg i))))
φ (CommFlatId (flat refl)) is not usable at the required modality .
when checking the definition of CommFlatId

Agda throws the same error with --cubical-compatible and if I understood #6236 correctly, once it is merged, Agda will also throw an error without any flag.

But, as I understand the flat modality in Agda, it should provide an approximation to what can be done with flat and sharp in real-cohesive hott (article). There, 'crisp identity induction' is derivable (Theorem 5.6 on p. 35), which is a general induction principle that would justify the pattern matching in the example above. The reasoning should apply to general inductive types.

So, considering what the flat modality in Agda should model, I think pattern matching on inductive families should be allowed and without any extra assumption, it should not be possible to derive anything new with this (up to adding '@♭' to derivable statements).

@felixwellen felixwellen added cubical Cubical Agda paraphernalia: Paths, Glue, partial elements, hcomp, transp modalities flat The @flat/@♭ modality labels Oct 26, 2022
@felixwellen felixwellen self-assigned this Oct 26, 2022
felixwellen added a commit to felixwellen/agda that referenced this issue Oct 26, 2022
felixwellen added a commit to felixwellen/agda that referenced this issue Oct 26, 2022
@nad
Copy link
Contributor

nad commented Oct 26, 2022

I seem to recall that every program that is accepted is also accepted if every reference to the cohesive modality is removed, and I suspect that all compiler backends ignore this modality. Thus your change is presumably "safe".

Is it the case that this modality is only used together with (unprovable) postulates or assumptions? In that case the question is perhaps if your change is compatible with the postulates or assumptions that users want to use.

@nad
Copy link
Contributor

nad commented Oct 26, 2022

Thus your change is presumably "safe".

But according to @plt-amy (see pull request #6239) the change makes some generated code fail the type-checker.

@plt-amy plt-amy added this to the 2.6.3 milestone Oct 27, 2022
@plt-amy plt-amy added the regression on master Unreleased regression in development version (Change to "regression in ..." should it be released!) label Oct 27, 2022
plt-amy pushed a commit to felixwellen/agda that referenced this issue Oct 27, 2022
plt-amy pushed a commit to felixwellen/agda that referenced this issue Oct 27, 2022
@plt-amy plt-amy added the documented-in-changelog Issues already documented in the CHANGELOG label Oct 28, 2022
plt-amy added a commit that referenced this issue Oct 28, 2022
* #6238: Add test case

* #6238: Suggested fix

* re #6237: forbid by default flat-split & without-K

When --flat-split and --cubical(-compatible) are used (which is not
--safe), --flat-split behaves as an injective flag. Furthermore, in that
case, the transpX clauses will not be generated for the function. (We
skip this by failing the LeftInv computation, so that a
NoEquivWhenSplitting warning is printed indicating the defn. won't
compute)

* mention in changelog that --cubical implies --no-flat-split

* fixup: update debug interaction test

* fixup: remove stray Nix file

* fixup: update changelog and remove 1 more stray file

* fixup: add test for --without-K as well

Co-authored-by: Amélia Liao <me@amelia.how>
@andreasabel
Copy link
Member

andreasabel commented Oct 29, 2022

Has this issue been fixed by

@plt-amy
Copy link
Member

plt-amy commented Oct 29, 2022

Yes. I'll write a follow-up issue to cover working out the proper interaction(s) between Cubical Agda and the modality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cubical Cubical Agda paraphernalia: Paths, Glue, partial elements, hcomp, transp documented-in-changelog Issues already documented in the CHANGELOG flat The @flat/@♭ modality modalities regression on master Unreleased regression in development version (Change to "regression in ..." should it be released!)
Projects
None yet
Development

No branches or pull requests

4 participants