tur/vec-existential
stdlib/vec-existential.tur
Vec[A] as a size-hiding existential for heterogeneous collections.
Since: Phase EX2
defmacro
vec-of-sized
(vec-of-sized [sv])
wrap a SizedVec into a Vec, hiding the size index.
Parameters
| sv | a SizedVec value whose size index will be sealed |
Returns
A value of type (exists [n] (SizedVec n int)) -- representable uniformly regardless of the original size index.
Example
(vec-of-sized (SVCons 1 (SVCons 2 (SVNil))))
; => packed Vec; opening it recovers a length-2 SizedVec.
Since: Phase EX2-4
defmacro
open-vec
(open-vec [vec-expr n-name sv-name & body])
bind the hidden size index and the underlying SizedVec.
Parameters
| vec-expr | a Vec value (typically produced by vec-of-sized) | |
| n-name | symbol that names the fresh abstract size index | |
| sv-name | symbol that names the underlying SizedVec | |
| body | one or more body forms evaluated in the binders' scope |
Returns
The value of the last body form.
Example
(open-vec (vec-of-sized (SVCons 1 (SVNil))) n sv
(sized-vec-len sv)) ; => 1
Since: Phase EX2-4