feat(library/init/data/array/basic): add shrink

This commit is contained in:
Leonardo de Moura 2019-04-07 12:42:56 -07:00
parent 97ebe4603b
commit 8d2d43beb2

View file

@ -12,8 +12,6 @@ universes u v w
The Compiler has special support for arrays.
They are implemented using dynamic arrays: https://en.wikipedia.org/wiki/Dynamic_array
-/
-- TODO(Leo): mark as opaque
structure Array (α : Type u) :=
(sz : Nat)
(data : Fin sz → α)
@ -107,6 +105,10 @@ def pop (a : Array α) : Array α :=
{ sz := Nat.pred a.sz,
data := λ ⟨j, h⟩, a.index ⟨j, Nat.ltOfLtOfLe h (Nat.predLe _)⟩ }
-- TODO(Leo): justify termination using wf-rec
partial def shrink : Array α → Nat → Array α
| a n := if a.size ≥ n then a else shrink a.pop n
section
variables {m : Type v → Type v} [Monad m]
local attribute [instance] monadInhabited'