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

Printing records in eta-contracted form let them look ill-typed sometimes #361

Open
GoogleCodeExporter opened this issue Aug 8, 2015 · 15 comments
Labels
eta contract Problem introduced by eta-contraction eta η-expansion of metavariables and unification modulo η records Record declarations, literals, constructors and updates type: bug Issues and pull requests about actual bugs
Milestone

Comments

@GoogleCodeExporter
Copy link

GoogleCodeExporter commented Aug 8, 2015

postulate
  A : Set

record R (a : A) : Set where
  constructor c
  field 
    p : A

postulate
  a b : A
  r : R a

Now,

  R.p {b} (c {b} (R.p {a} r)

reduces to the ill-typed

  R.p {b} r

instead of R.p {a} r

Original issue reported on code.google.com by andreas....@gmail.com on 12 Nov 2010 at 12:58

@GoogleCodeExporter
Copy link
Author

GoogleCodeExporter commented Aug 8, 2015

Looks almost as if this reduction is the result of an eta-contraction

  c {b} (R.p {a} r) -> r

Original comment by andreas....@gmail.com on 12 Nov 2010 at 2:23

@GoogleCodeExporter GoogleCodeExporter added Priority-Low type: bug Issues and pull requests about actual bugs eta η-expansion of metavariables and unification modulo η labels Aug 8, 2015
@GoogleCodeExporter
Copy link
Author

GoogleCodeExporter commented Aug 8, 2015

To precise the report, the problem appears only in the form with a definition

relabel : R a -> R b
relabel r = c {b} (R.p {a} r)

R.p {b} (relabel r) reduces to R.p {b} r

The manually expanded term

  R.p {b} (c {b} (R.p {a} r)

reduces correctly to R.p {a} r.

Must be that the body of relabel is eta-contracted or something like that.

Original comment by andreas....@gmail.com on 12 Nov 2010 at 2:47

@GoogleCodeExporter
Copy link
Author

GoogleCodeExporter commented Aug 8, 2015

The buggy behavior disappears if I skip eta-contraction of function bodies.
This is done by removing the line

  cs <- instantiateFull =<< mapM rebindClause cs

in Def.hs/checkFunDef. rebindClause is the identity, instantiateFull eta-contracts. Without this line the body of relabel is kept as is and not eta-contracted to r.

As a side effect, test/fail/Issue259.agda now type-checks.

How can I document this issue in the test suite? How can I write a test-case that ensures that a certain eta-contraction is not carried out? (When the type-checker works modulo eta...)

Original comment by andreas....@gmail.com on 12 Nov 2010 at 5:48

@GoogleCodeExporter
Copy link
Author

Original comment by andreas....@gmail.com on 12 Nov 2010 at 5:52

  • Changed title: Record eta-contraction (of function bodies) breaks well-typedness

@GoogleCodeExporter
Copy link
Author

GoogleCodeExporter commented Aug 8, 2015

Undid my fix because it breaks Data.Star.Decoration of the std-lib.
Also, Simon Forster reports that fix was not complete.

Original comment by andreas....@gmail.com on 16 Nov 2010 at 10:37

@GoogleCodeExporter
Copy link
Author

GoogleCodeExporter commented Aug 8, 2015

Now this triggers an error message, which it should not. Eta-contraction for records is a solid bug:

data _==_ {A : Set}(a : A) : A -> Set where
  refl : a == a

postulate
  A : Set
  a b : A
  F : A -> Set

record R (a : A) : Set where
  constructor c
  field 
    p : A

beta : (x : A) -> R.p {b} (c {b} x) == x
beta x = refl

lemma : (r : R a) -> R.p {b} (c {b} (R.p {a} r)) == R.p {a} r
lemma r = beta (R.p {a} r)

{-
    a != b of type A
    when checking that the expression beta (R.p {a} r) has type
    _==_ {A} (R.p {b} r) (R.p {a} r)
-}

Original comment by andreas....@gmail.com on 16 Nov 2010 at 11:45

Attachments:

@GoogleCodeExporter
Copy link
Author

Original comment by nils.anders.danielsson on 19 Jan 2011 at 5:12

  • Added labels: Eta

@GoogleCodeExporter
Copy link
Author

GoogleCodeExporter commented Aug 8, 2015

The example in Comment 6 no longer triggers an error message.

Original comment by nils.anders.danielsson on 2 Sep 2011 at 7:00

@GoogleCodeExporter
Copy link
Author

GoogleCodeExporter commented Aug 8, 2015

Closing this.

Original comment by ulf.nor...@gmail.com on 2 Sep 2011 at 8:03

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

One or more problems in Issue361.agda remain.

Original comment by nils.anders.danielsson on 2 Sep 2011 at 8:27

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

One or more problems?  Anything that isn't just printing?

Original comment by ulf.nor...@gmail.com on 2 Sep 2011 at 8:48

@GoogleCodeExporter
Copy link
Author

GoogleCodeExporter commented Aug 8, 2015

postulate
  A   : Set
  a b : A

record R (_ : A) : Set where
  constructor c
  field
    p : A

postulate
  r : R a

relabel : R a  R b
relabel r = c {b} (R.p {a} r)

-- Type of r: R a.
-- Type of relabel r: R b.
--
-- If we normalise relabel r we get r, which does not have type R b,
-- so it seems as if subject reduction is broken.

-- r-does-not-have-type-R-b : R b
-- r-does-not-have-type-R-b = r

Original comment by nils.anders.danielsson on 3 Sep 2011 at 4:40

@GoogleCodeExporter
Copy link
Author

That is just printing. relabel r doesn't normalise to r, we just print it as r. 
Eta contracting the output helps a lot when working with big records. I don't 
think it's worth losing that over this.

Original comment by ulf.nor...@gmail.com on 4 Sep 2011 at 7:09

  • Added labels: Priority-Low
  • Removed labels: Priority-High

@GoogleCodeExporter
Copy link
Author

No plans to fix this in the near future, since problem is minor and fix 
substantial.

Original comment by andreas....@gmail.com on 11 Sep 2011 at 7:08

  • Changed title: Printing records in eta-contracted form let them look ill-typed sometimes

@andreasabel andreasabel added records Record declarations, literals, constructors and updates and removed auto-migrated labels Feb 3, 2018
@andreasabel
Copy link
Member

Here is an example using lambda.

postulate
  A : Set
  B : A  Set

data D (x : A) : Set where
  c : (B x  B x)  A  D x

test : (x : A)  D x
test = λ x  c (λ (y : B x)  y) x

-- Agda eta-contracts this to the following, which is not well-typed.

-- foo : (x : A) → D x
-- foo = c λ y → y

-- Cannot instantiate the metavariable _11 to solution x since it
-- contains the variable x which is not in scope of the metavariable
-- or irrelevant in the metavariable but relevant in the solution
-- when checking that the expression c λ y → y has type (x : A) → D x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eta contract Problem introduced by eta-contraction eta η-expansion of metavariables and unification modulo η records Record declarations, literals, constructors and updates type: bug Issues and pull requests about actual bugs
Projects
None yet
Development

No branches or pull requests

4 participants