chore: missing GetElem instances

This commit is contained in:
Leonardo de Moura 2022-07-10 14:53:22 -07:00
parent fd0e9e1c52
commit 475c7e18cd
3 changed files with 9 additions and 3 deletions

View file

@ -41,7 +41,7 @@ def singleton (v : α) : Array α :=
def uget (a : @& Array α) (i : USize) (h : i.toNat < a.size) : α :=
a[i.toNat]
instance : GetElem (Array α) USize α fun xs i => LT.lt i.toNat xs.size where
instance : GetElem (Array α) USize α fun xs i => i.toNat < xs.size where
getElem xs i h := xs.uget i h
def back [Inhabited α] (a : Array α) : α :=

View file

@ -49,9 +49,12 @@ def get! : (@& ByteArray) → (@& Nat) → UInt8
def get : (a : @& ByteArray) → (@& Fin a.size) → UInt8
| ⟨bs⟩, i => bs.get i
instance : GetElem ByteArray Nat UInt8 fun xs i => LT.lt i xs.size where
instance : GetElem ByteArray Nat UInt8 fun xs i => i < xs.size where
getElem xs i h := xs.get ⟨i, h⟩
instance : GetElem ByteArray USize UInt8 fun xs i => i.val < xs.size where
getElem xs i h := xs.uget i h
@[extern "lean_byte_array_set"]
def set! : ByteArray → (@& Nat) → UInt8 → ByteArray
| ⟨bs⟩, i, b => ⟨bs.set! i b⟩

View file

@ -55,9 +55,12 @@ def get? (ds : FloatArray) (i : Nat) : Option Float :=
else
none
instance : GetElem FloatArray Nat Float fun xs i => LT.lt i xs.size where
instance : GetElem FloatArray Nat Float fun xs i => i < xs.size where
getElem xs i h := xs.get ⟨i, h⟩
instance : GetElem FloatArray USize Float fun xs i => i.val < xs.size where
getElem xs i h := xs.uget i h
@[extern "lean_float_array_uset"]
def uset : (a : FloatArray) → (i : USize) → Float → i.toNat < a.size → FloatArray
| ⟨ds⟩, i, v, h => ⟨ds.uset i v h⟩