agda / agda

Agda is a dependently typed programming language / interactive theorem prover.

Home Page:https://wiki.portal.chalmers.se/agda/pmwiki.php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Recursion with records

txa opened this issue · comments

I am running into this problem several times. When I define a universe using a record the positivity checker complains but if I replace the record with an ugly Sigma type it is ok. Is this a known issue? Any chance of fixing it?

Here is an example :

data U : Set
El : U  Set

data U where
  σ : (A : U)(B : El A  U)  U

record El-σ(A : U)(B : El A  U) : Set where
  inductive -- why?
  field
    fst : El A
    snd : (x : El A)  El (B x)

El (σ A B) = El-σ A B

leads to an error. Actually I don't want the record to be inductive but if I leave this out I also get an error (this is wrong). But if I use a product it works:

data U : Set
El : U  Set

data U where
  σ : (A : U)(B : El A  U)  U

El (σ A B) = (El A) × ((x : El A)  El (B x)) -- El-σ 

See the discussion on Zulip.

Positivity checking is not integrated with termination checking, see:

  • #4563 (Your issue might be a duplicate of this one.)

So you cannot write things like

data Ty : Set where
  arr : (a b : Ty) -> Ty

variable a b : Ty

data Sem : Ty -> Set where
  fun : (Sem a -> Sem b) -> Sem (arr a b)

Instead, you need ugly recursive definitions:

Sem : Ty -> Set
Sem (arr a b) = Sem a -> Sem b

Your example mutually defines U, El and El-sigma and El-sigma uses El negatively (which in turn uses El-sigma positively). So the positivity checker rejects it. The positivity checker is a syntactic device, it does not care about whether there is a semantically equivalent definitions that would be accepted.

Really we would like to fix #4563. This would albeit have semantic implications: a data is then no longer always a conventional inductive type.