feat: a[i] and a[i]! notation for Subarrays

This commit is contained in:
Leonardo de Moura 2022-07-02 15:54:34 -07:00
parent a2456c3a0f
commit 54c60d4c2d
2 changed files with 8 additions and 5 deletions

View file

@ -29,13 +29,16 @@ def get (s : Subarray α) (i : Fin s.size) : α :=
exact Nat.add_lt_of_lt_sub this
s.as[s.start + i.val, this]
@[inline] def getD (s : Subarray α) (i : Nat) (v₀ : α) : α :=
if h : i < s.size then s[i, h] else v₀
abbrev getOp (self : Subarray α) (idx : Fin self.size) : α :=
self.get idx
def get! [Inhabited α] (s : Subarray α) (i : Nat) : α :=
@[inline] def getD (s : Subarray α) (i : Nat) (v₀ : α) : α :=
if h : i < s.size then s.get ⟨i, h⟩ else v₀
abbrev get! [Inhabited α] (s : Subarray α) (i : Nat) : α :=
getD s i default
def getOp [Inhabited α] (self : Subarray α) (idx : Nat) : α :=
abbrev getOp! [Inhabited α] (self : Subarray α) (idx : Nat) : α :=
self.get! idx
def popFront (s : Subarray α) : Subarray α :=

View file

@ -633,7 +633,7 @@ private partial def mkEquationsFor (matchDeclName : Name) : MetaM MatchEqns :=
let altNonEqNumParams := altNumParams - numDiscrEqs
let thmName := baseName ++ ((`eq).appendIndexAfter idx)
eqnNames := eqnNames.push thmName
let (notAlt, splitterAltType, splitterAltNumParam, argMask) ← forallAltTelescope (← inferType alts[i]) altNonEqNumParams fun ys eqs rhsArgs argMask altResultType => do
let (notAlt, splitterAltType, splitterAltNumParam, argMask) ← forallAltTelescope (← inferType alts[i]!) altNonEqNumParams fun ys eqs rhsArgs argMask altResultType => do
let patterns := altResultType.getAppArgs
let mut hs := #[]
for notAlt in notAlts do