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 all

Basic 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:

Compile a function using the type:

Wolfram Research (2022), LiteralType, Wolfram Language function, https://reference.wolfram.com/language/ref/LiteralType.html.

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

BibTeX

@misc{reference.wolfram_2022_literaltype, author="Wolfram Research", title="{LiteralType}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/LiteralType.html}", note=[Accessed: 19-August-2022 ]}

BibLaTeX

@online{reference.wolfram_2022_literaltype, organization={Wolfram Research}, title={LiteralType}, year={2022}, url={https://reference.wolfram.com/language/ref/LiteralType.html}, note=[Accessed: 19-August-2022 ]}