Closed timsueberkrueb closed 4 years ago
Problem #3 is an interesting one and it's different from #302.
The right way to go would be changing the type of count
to start with count : {0 ctx : Vect len Typ} -> ...
. That should check because the constructor tag is forced and its fields end up unused or in erased recursive positions. (This is easily visible in the compiled form of count
: there's a single-branch case match on the vector, and all its fields are unused, except for its tail in the recursive call.)
However, it does not check currently; probably because the implemented rules are a bit too strict.
Problem 3 at least is because ctx
has unrestricted usage in the type of count
, but you've said you're not going to use it in the type of notAccessible
. There may be some more complicated reason why it's not needed, as @ziman says, but usage checking beyond what's in the type is quite conservative.
Ah, I see. Explicitly specifying len
and ctx
works:
notAccessible : {len : Nat} -> {ctx : Vect len Typ} -> Term (TLam TNat (TLam TNat TNat)) ctx
notAccessible = Lam (Lam (Var (count 0)))
Okay, I see what's going on here. Essentially, it means I need to implement the occurs check properly, which is something I've meant to do for ages. What it was trying to do was solve this constraint:
?ctx =?= TLam TNat (lookup (TNat :: ?ctx) FZ) :: ctx
...and the naive solution has a cycle because the definition uses ?ctx
itself. This is okay in Idris 1 because it normalises all over the place, and normalising the RHS of this equation evaluates lookup
, so it just resolves to TLam TNat TNat :: ctx
, which is what we want.
I've implemented a fix, though I haven't run all the tests yet, so expect a patch soonish. Hopefully it's related to #68, I'll test that later.
Awesome, thank you. Here is the complete file in case that can help with testing the patch: https://gist.github.com/timsueberkrueb/5275cb940258f833800fd7c864f81759
Hey, I stumbled upon some issues while working through plfa, chapter DeBruijn. Note that the code below compiles fine in Idris 1 but Idris 2 has some problems with it.
... this compiles just fine. Here comes the trouble:
Problem 1
Problem 2 (probably #68)
Problem 3 (probably #302)