数组索引要求有证据表明相应索引位于数组边界内,因此 getThird 无法精译。
def getThird (xs : Array α) : α := failed to prove index is valid, possible solutions:
- Use `have`-expressions to prove the index is valid
- Use `a[i]!` notation instead, runtime check is performed, and 'Panic' error message is produced if index is not valid
- Use `a[i]?` notation instead, result is an `Option` type
- Use `a[i]'h` notation instead, where `h` is a proof that index is valid
α:Type ?u.3xs:Array α⊢ 2 < xs.sizexs[2]
failed to prove index is valid, possible solutions:
- Use `have`-expressions to prove the index is valid
- Use `a[i]!` notation instead, runtime check is performed, and 'Panic' error message is produced if index is not valid
- Use `a[i]?` notation instead, result is an `Option` type
- Use `a[i]'h` notation instead, where `h` is a proof that index is valid
α:Type ?u.3xs:Array α⊢ 2 < xs.size
将返回类型放宽为 Option 并添加边界检查后,仍会得到相同的错误。
这是因为索引位于边界内的证明没有被加入局部上下文。
def getThird (xs : Array α) : Option α :=
if xs.size ≤ 2 then none
else failed to prove index is valid, possible solutions:
- Use `have`-expressions to prove the index is valid
- Use `a[i]!` notation instead, runtime check is performed, and 'Panic' error message is produced if index is not valid
- Use `a[i]?` notation instead, result is an `Option` type
- Use `a[i]'h` notation instead, where `h` is a proof that index is valid
α:Type ?u.3xs:Array α⊢ 2 < xs.sizexs[2]
failed to prove index is valid, possible solutions:
- Use `have`-expressions to prove the index is valid
- Use `a[i]!` notation instead, runtime check is performed, and 'Panic' error message is produced if index is not valid
- Use `a[i]?` notation instead, result is an `Option` type
- Use `a[i]'h` notation instead, where `h` is a proof that index is valid
α:Type ?u.3xs:Array α⊢ 2 < xs.size
为证明命名为 h,就足以使执行边界检查的策略成功,尽管它并未显式出现在程序文本中。
def getThird (xs : Array α) : Option α :=
if h : xs.size ≤ 2 then none
else xs[2]