LiteralType
LiteralType[x]
represents a literal value x for use as a type.
Details
- LiteralType is often used as a parameter of other types. For example, the rank of a packed array is represented with a literal type "PackedArray"::["MachineInteger",LiteralType[2]].
- In some cases, LiteralType is added implicitly, such as in "PackedArray"::["MachineInteger",2].
- Literal types can be integers, strings or Boolean values.
- The head LiteralType can generally be omitted for integer and Boolean values, but is required for string values.
Examples
open allclose allBasic Examples (1)
Compile a program for manipulating packed arrays whose types are represented with LiteralType:
Scope (2)
Define a function to have different return types depending on a literal type argument:
Compile a function using the first usage:
Compile a function using the second usage:
Use TypeEvaluate to transform literal types in a function signature:
Text
Wolfram Research (2022), LiteralType, Wolfram Language function, https://reference.wolfram.com/language/ref/LiteralType.html.
CMS
Wolfram Language. 2022. "LiteralType." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/LiteralType.html.
APA
Wolfram Language. (2022). LiteralType. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LiteralType.html