tur/existential
stdlib/existential.tur
helpers for native pack/open existential types.
Since: Phase EX1
defmacro
showable
(showable [x])
pack a value as a Show-constrained existential.
Parameters
| x | any value whose type implements the Show typeclass |
Returns
A boxed existential of type (exists [a] [(Show a)] a). At runtime this is a tur_existential_t* carrying the value and a Show vtable pointer (see Phase EX1e).
Example
(showable 42)
; => packed existential; opening it with show-it prints "42".
Since: Phase EX1f
defmacro
show-it
(show-it [s])
open a Show-constrained existential and call .show on
Parameters
| s | a value of type (exists [a] [(Show a)] a) produced by showable |
Returns
The :cstr produced by the Show instance attached to the underlying concrete type.
Example
(show-it (showable 42)) ; => "42" (show-it (showable true)) ; => "true" (requires Show [bool])
Since: Phase EX1f