Skip to content

Commit 9694728

Browse files
authored
doc: reference mkEmpty in Array doc-string (#7430)
This PR explains how to use `Array.mkEmpty` to specify the capacity of a new array, from the `Array` doc-string.
1 parent 0af15f9 commit 9694728

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Init/Prelude.lean

+5-2
Original file line numberDiff line numberDiff line change
@@ -2652,12 +2652,15 @@ attribute [nospecialize] Inhabited
26522652
`Array α` is the type of [dynamic arrays](https://en.wikipedia.org/wiki/Dynamic_array)
26532653
with elements from `α`. This type has special support in the runtime.
26542654
2655-
An array has a size and a capacity; the size is `Array.size` but the capacity
2656-
is not observable from Lean code. Arrays perform best when unshared; as long
2655+
Arrays perform best when unshared; as long
26572656
as they are used "linearly" all updates will be performed destructively on the
26582657
array, so it has comparable performance to mutable arrays in imperative
26592658
programming languages.
26602659
2660+
An array has a size and a capacity; the size is `Array.size` but the capacity
2661+
is not observable from Lean code. `Array.mkEmpty n` creates an array which is equal to `#[]`,
2662+
but internally allocates an array of capacity `n`.
2663+
26612664
From the point of view of proofs `Array α` is just a wrapper around `List α`.
26622665
-/
26632666
structure Array (α : Type u) where

0 commit comments

Comments
 (0)