The class GetElem coll idx elem valid
implements the xs[i]
notation.
Given xs[i]
with xs : coll
and i : idx
, Lean looks for an instance of
GetElem coll idx elem valid
and uses this to infer the type of return
value elem
and side conditions valid
required to ensure xs[i]
yields
a valid value of type elem
.
For example, the instance for arrays looks like
GetElem (Array α) Nat α (fun xs i => i < xs.size)
.
The proof side-condition valid xs i
is automatically dispatched by the
get_elem_tactic
tactic, which can be extended by adding more clauses to
get_elem_tactic_trivial
.
- getElem : (xs : coll) → (i : idx) → valid xs i → elem
The syntax
arr[i]
gets thei
'th element of the collectionarr
. If there are proof side conditions to the application, they will be automatically inferred by theget_elem_tactic
tactic.The actual behavior of this class is type-dependent, but here are some important implementations:
arr[i] : α
wherearr : Array α
andi : Nat
ori : USize
: does array indexing with no bounds check and a proof side goali < arr.size
.l[i] : α
wherel : List α
andi : Nat
: index into a list, with proof side goali < l.length
.stx[i] : Syntax
wherestx : Syntax
andi : Nat
: get a syntax argument, no side goal (returns.missing
out of range)
There are other variations on this syntax:
Instances
The syntax arr[i]
gets the i
'th element of the collection arr
. If there
are proof side conditions to the application, they will be automatically
inferred by the get_elem_tactic
tactic.
The actual behavior of this class is type-dependent, but here are some important implementations:
arr[i] : α
wherearr : Array α
andi : Nat
ori : USize
: does array indexing with no bounds check and a proof side goali < arr.size
.l[i] : α
wherel : List α
andi : Nat
: index into a list, with proof side goali < l.length
.stx[i] : Syntax
wherestx : Syntax
andi : Nat
: get a syntax argument, no side goal (returns.missing
out of range)
There are other variations on this syntax:
arr[i]!
is syntax forgetElem! arr i
which should panic and returndefault : α
if the index is not valid.arr[i]?
is syntax forgetElem?
which should returnnone
if the index is not valid.arr[i]'h
is syntax forgetElem arr i h
withh
an explicit proof the index is valid.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The syntax arr[i]
gets the i
'th element of the collection arr
. If there
are proof side conditions to the application, they will be automatically
inferred by the get_elem_tactic
tactic.
The actual behavior of this class is type-dependent, but here are some important implementations:
arr[i] : α
wherearr : Array α
andi : Nat
ori : USize
: does array indexing with no bounds check and a proof side goali < arr.size
.l[i] : α
wherel : List α
andi : Nat
: index into a list, with proof side goali < l.length
.stx[i] : Syntax
wherestx : Syntax
andi : Nat
: get a syntax argument, no side goal (returns.missing
out of range)
There are other variations on this syntax:
arr[i]!
is syntax forgetElem! arr i
which should panic and returndefault : α
if the index is not valid.arr[i]?
is syntax forgetElem?
which should returnnone
if the index is not valid.arr[i]'h
is syntax forgetElem arr i h
withh
an explicit proof the index is valid.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The syntax arr[i]?
gets the i
'th element of the collection arr
or
returns none
if i
is out of bounds.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The syntax arr[i]!
gets the i
'th element of the collection arr
and
panics i
is out of bounds.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- ⋯ = ⋯
Equations
- ⋯ = ⋯
Equations
- ⋯ = ⋯
Equations
- One or more equations did not get rendered due to their size.