lean4-htt/tests/lean/funind_errors.lean
Joachim Breitner ab318dda2d
feat: use reserved name infrastructure for functional induction (#3776)
no need to enter `derive_functional_induction` anymore.

(Will remove the support for `derive_functional_induction` after the
next stage0 update, since we are already using it in Init.)
2024-03-26 22:25:10 +00:00

45 lines
1.2 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Some of these tests made more sense when we had a
-- derive_functional_induction command.
#check doesNotExist.induct
def takeWhile (p : α → Bool) (as : Array α) : Array α :=
foo 0 #[]
where
foo (i : Nat) (r : Array α) : Array α :=
if h : i < as.size then
let a := as.get ⟨i, h⟩
if p a then
foo (i+1) (r.push a)
else
r
else
r
termination_by as.size - i
-- Checks the error message when the users tries to access the induct rule for the wrong function
-- (before we used reserved names for this feature we did give a more helpful error message here)
#check takeWhile.induct
#check takeWhile.foo.induct
-- this tests the error we get when trying to access the induct rules for
-- a function that recurses over an inductive *predicate* (not yet supported)
inductive Even : Nat → Prop where
| zero : Even 0
| plus2 : Even n → Even (n + 2)
def idEven : Even n → Even n
| .zero => .zero
| .plus2 p => .plus2 (idEven p)
#check idEven.induct
-- this tests the error we get when trying to access the induct rules for
-- a function that recurses over `Acc`
def idAcc : Acc p x → Acc p x
| Acc.intro x f => Acc.intro x (fun y h => idAcc (f y h))
#check idAcc.induct