Skip to content

The type of a data constructor should *not* have repeated indices unless defined within the scope of with-K #2519

Open

Description

@jamesmckinna

See the discussion on #2504 for a specific instance.

This raises the issue to library level, given the ambient stdlib assumption of cubical-compatible/without-K.

data constructors which exploit repeated occurrences/'non-linearity' are making implicit appeal to reflexivity of (propositional) equality, and that should instead be required as an explicit witness. Specialising the constructor to supply refl as a default witness should be the preferred approach to offering a non-linear constructor. Cf. Data.Nat.Divisibility.Core #2013

Activity

  1. added
    cubical-compatible
    on Dec 12, 2024
  2. MatthewDaggitt commented on Dec 16, 2024

    @MatthewDaggitt
    Collaborator

    I agree this is a good principle going forward. However, how many definitions fall foul of this currently? Depending on the numbers I would be weary of how big a breaking change this would be to change all the existing definitions?

  3. jamesmckinna commented on Dec 16, 2024

    @jamesmckinna
    CollaboratorAuthor

    I haven't done a survey of the relevant definitions, besides Data.Nat.Base._≤′_, which seems to fall even more easily to the corresponding refactoring as #2504 . See commit jamesmckinna@895cd32 on branch jamesmckinna/issue2519 which is ready-to-go as a PR if you think it's worthwhile.

    More generally, I'd advocate piecemeal refactoring in the interests of avoiding 'large' breaking changes?

  4. JacquesCarette commented on Dec 17, 2024

    @JacquesCarette
    Collaborator

    I agree with the design principle.

    My gut feel is that this isn't likely to occur very often. But this is rather hard to search for! So piecemeal refactoring is indeed a rather reasonable way to go.

  5. Taneb commented on Dec 19, 2024

    @Taneb
    Member

    Can you clarify what exactly you mean by "non-linear" here? Is it that the same variable should not appear in two different indices of a data constructor?

  6. jamesmckinna commented on Dec 19, 2024

    @jamesmckinna
    CollaboratorAuthor

    Can you clarify what exactly you mean by "non-linear" here? Is it that the same variable should not appear in two different indices of a data constructor?

    Yes, exactly. I'll change the title of the issue.

    In the originating PR #2504 it's actually even stronger than that, because it meant that those indices could even become parameters to the data definition.

  7. changed the title [-]`data` constructors should *not* be non-linear unless defined within the scope of `with-K`[/-] [+]The type of a `data` constructor should *not* have repeated indices unless defined within the scope of `with-K`[/+] on Dec 19, 2024
  8. jamesmckinna commented on Aug 1, 2026

    @jamesmckinna
    CollaboratorAuthor

    Looping back to #1344 ... where @MatthewDaggitt had the same idea, but with different motivations, in this comment.

  9. added and removed
    cubical-compatible
    on Aug 1, 2026
  10. jamesmckinna commented on Nov 19, 2026

    @jamesmckinna
    CollaboratorAuthor

    Another example (but yes: they are quite hard to identify...): in Data.Bool.Base

    data _≤_ : Bool → Bool → Set where
      f≤t : false ≤ true
      b≤b : ∀ {b} → b ≤ b

    which should (probably; at least on the model of this proposal...) become

    data _≤_ : Bool → Bool → Set where
      f≤t : false ≤ true
      ≤-reflexive : ∀ {x y} → x ≡ y → x ≤ y
    
    pattern b≤b = ≤-reflexive refl
  11. Taneb commented on Nov 19, 2026

    @Taneb
    Member

    I'm not convinced by this one, given that we can prove K specialised to Bool, and this isn't some example of a wider pattern - or is it? No, this definition now looks a lot like Relation.Binary.Construct.StrictToNonStrict!

  12. jamesmckinna commented on Nov 19, 2026

    @jamesmckinna
    CollaboratorAuthor

    Thanks @shhyou for the endorsement, and also to @Taneb for the pushback.

    Regarding the latter, for sure we can prove K for Bool, but such proof/knowledge is after-the-fact (and would need to be in Data.Bool.Properties) relative to the definition here, which for Reasons, we put such 'basic' relations in Data.X.Base...

    The observation that it might now be an instance of a construction is... all to the good, as far as a subsequent refactoring would be concerned, and indeed as far as I am (!), because the strict relations (here, and in Data.Nat.Base) are, for me, indeed conceptually prior to the non-strict.

    UPDATED possibly also further fuel for @JacquesCarette 's desire to move such things into... smaller submodules under Data.X?

    In the meantime, you were too quick! I've just pushed #3152 ... followup discussions there for the Bool instance?

  13. shhyou commented on Nov 19, 2026

    @shhyou
    Contributor

    But then,

    {-# OPTIONS --without-K #-}
    
    module _ where
    
    open import Data.Bool.Base
    open import Relation.Binary.PropositionalEquality
    
    ar : ∀ b c → b ≤ c → c ≤ b → b ≡ c
    ar b c b≤b c≤b = {!c≤b!}
    {-
    Agda version 2.10.0-be0acfe:
    
    bo.agda:9.18-19: error: [SplitError.UnificationStuck]
    I'm not sure if there should be a case for the constructor b≤b,
    because I get stuck when trying to solve the following unification
    problems (inferred index ≟ expected index):
      b₁ ≟ b₂
      b₁ ≟ b₂
    Possible reason why unification failed:
      Cannot eliminate reflexive equation b₁ = b₁ of type Bool because K
      has been disabled.
    when checking that the expression ? has type b ≡ b
    -}

    (Matching b and c instead of b≤c and c≤b solves the problem, of course.)

  14. jamesmckinna commented on Nov 19, 2026

    @jamesmckinna
    CollaboratorAuthor

    But... without having to match on the implicits, and matching on the first relational argument:

    ≤-antisym : Antisymmetric _≡_ _≤_
    ≤-antisym (≤-reflexive eq) _ = eq
    ≤-antisym f≤t (≤-reflexive ())

    And, indeed, if we took @Taneb 's suggestion, then ≤-antisym follows from general considerations of <-trans and <-irrefl.

    UPDATED: see branch https://github.com/jamesmckinna/agda-stdlib/tree/bool-issue2519-bis which is based on this PR for emerging development, not yet ready even as a DRAFT PR.

  15. jamesmckinna commented on Nov 20, 2026

    @jamesmckinna
    CollaboratorAuthor

    Apologies @shhyou I misread your last comment. Is this a v2.10 problem, or do we have inductive-family-related warnings turned off in stdlib which avoid this problem? I'm puzzled now... as the code I did offer typechecks under v2.9.0. Any idea what's happened/happening?

  16. shhyou commented on Nov 23, 2026

    @shhyou
    Contributor

    I just support changing b≤b to ≤-reflexive eq because the former definition does not allow the natural pattern-matching proofs without K (although in the specific case above matching on c≤b is redundant).

  17. jamesmckinna commented on Nov 27, 2026

    @jamesmckinna
    CollaboratorAuthor

    See also, In the wider context of this issue, the discussion in #1344 about Closure.Reflexive...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions