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

let: unexpected generalization of variable #5683

Closed
omelkonian opened this issue Dec 3, 2021 · 5 comments · Fixed by #5684
Closed

let: unexpected generalization of variable #5683

omelkonian opened this issue Dec 3, 2021 · 5 comments · Fixed by #5684
Labels
generalize Related to generalisable variables let Issues relating to let expressions type: bug Issues and pull requests about actual bugs
Milestone

Comments

@omelkonian
Copy link
Contributor

Agda 2.6.2.0.20211129

When using generalized variables in a constructor, I expect to get the same behaviour as if I had explicitly introduced it with a ∀ quantifier.
This breaks by the following MWE:

postulate
  X : Set
  ∀≡ :  (x : X)  x ≡ x

variable  x : X

data C : Σ X (λ x  x ≡ x)  Set where
  _ :
    -- works if I remove this comment
    -- ∀ {x} → 
    let
      eq : x ≡ x
      eq = ∀≡ x
    in
    C (x , eq)
x != x of type X
(because one has de Bruijn index 1 and the other 0)
when checking that the expression ∀≡ x has type x ≡ x

It seems that the let-clause does its own generalization (producing x = # 0) and shadows the previous x = # 1.

@UlfNorell
Copy link
Member

The fix would be to not generalize types if you are already in scope of a generalization. This makes sense I think.

@omelkonian
Copy link
Contributor Author

If you mean the fix is to disallow any (nested) generalization, it might be too limiting. What I would expect is to never re-generalise a variable with the same name.

@UlfNorell
Copy link
Member

I'm not sure it would be that limiting. It's very close to the principle that says we don't generalize the type of eq in

_ : (eq : x ≡ x) -> C (x , eq)

@omelkonian
Copy link
Contributor Author

If I understood correctly, the fix would disallow C⁺ because there is a generalized x in scope, but allow C⁻?
(currently both are accepted)

postulate
  X : Set
  ∀≡ :  {x y : X}  x ≡ y

variable x y : X

data C⁻ : ( {x : X}  x ≡ x)  Set where
  _ :
    let
      eq : y ≡ y
      eq = ∀≡
    in
    C⁻ eq

data C⁺ : X  ( {x : X}  x ≡ x)  Set where
  _ :
    let
      eq : y ≡ y
      eq = ∀≡
    in
    C⁺ x eq

@UlfNorell
Copy link
Member

No I was thinking it would disallow both. The generalization point in both examples would be the top-level type.

@andreasabel andreasabel added generalize Related to generalisable variables let Issues relating to let expressions type: bug Issues and pull requests about actual bugs labels Dec 5, 2021
omelkonian added a commit that referenced this issue Dec 7, 2021
omelkonian added a commit that referenced this issue Dec 8, 2021
@andreasabel andreasabel added this to the 2.6.2.2 milestone Mar 14, 2022
@andreasabel andreasabel mentioned this issue Mar 14, 2022
41 tasks
andreasabel pushed a commit that referenced this issue Mar 14, 2022
andreasabel pushed a commit that referenced this issue Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generalize Related to generalisable variables let Issues relating to let expressions type: bug Issues and pull requests about actual bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants