-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: mutual recursion: allow common prefix up to alpha-equivalence (#…
…5041) @arthur-adjedj was very confused when a mutually recursive definition didn't work as expected, and the reason was that he used different names for the fixed parameters. It seems plausible to simply allow that and calculate the fixed-prefix up to alpha renaming. It does mean, though, that, for example, termination proof goals will mention the names as used by the first function. But probably better than simply failing. And we could even fix that later (by passing down the actual names, and renmaing the variables in the context of the mvar, depending on the “current function”) should it bother our users.
- Loading branch information
Showing
3 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace Structural | ||
mutual | ||
def f1 (α : Type) : List α → Nat | ||
| [] => 0 | ||
| _ :: xs => f2 α xs + 1 | ||
termination_by structural n => n | ||
|
||
-- NB β, not α. Used to prevent this from working (with an unhelpful error message) | ||
def f2 (β : Type) : List β → Nat | ||
| [] => 0 | ||
| _ :: xs => f1 β xs + 1 | ||
termination_by structural n => n | ||
end | ||
end Structural | ||
|
||
namespace WF | ||
|
||
mutual | ||
def f1 (α : Type) : List α → Nat | ||
| [] => 0 | ||
| _ :: xs => f2 α xs + 1 | ||
termination_by n => n | ||
|
||
-- NB β, not α. Used to prevent this from working (with an unhelpful error message) | ||
def f2 (β : Type) : List β → Nat | ||
| [] => 0 | ||
| _ :: xs => f1 β xs + 1 | ||
termination_by n => n | ||
decreasing_by | ||
-- NB: The proof goal for `f2` mentions `α`, not `β`. Could be fixed in theory if we really care | ||
guard_hyp α : Type | ||
decreasing_tactic | ||
end | ||
end WF |