Typed[expr,type]
represents an expression that should be assumed to be of a specified type for compilation and other purposes.
Typed[expr,type]
represents an expression that should be assumed to be of a specified type for compilation and other purposes.
Details
- Function[{Typed[x1,type1], …}, …] can be used to specify argument types to be accepted by a Function object for compilation and other purposes.
- The types supported by Typed include:
-
"name" an object with a native type of the specified name {type1,type2,…}type a function taking arguments of type typei and returning the specified type cons::[type1,type2,...] an object with a compound type created using the constructor cons - Native types supported by Typed include:
-
"Boolean" Boolean "ComplexReal64" complex number with IEEE double‐precision real and imaginary parts "Integer8" 8‐bit signed integer "Integer16" 16‐bit signed integer "Integer32" 32‐bit signed integer "Integer64" 64‐bit signed integer "Integer128" 128‐bit signed integer "MachineInteger" machine‐sized signed integer "Real32" IEEE single‐precision real number "Real64" IEEE double‐precision real number "UnsignedInteger8" 8‐bit unsigned integer "UnsignedInteger16" 16‐bit unsigned integer "UnsignedInteger32" 32‐bit unsigned integer "UnsignedInteger64" 64‐bit unsigned integer "UnsignedInteger128" 128‐bit unsigned integer "UnsignedMachineInteger" machine-sized unsigned integer
Examples
open all close allBasic Examples (4)
Typed specifies the type of function arguments:
f = Function[Typed[arg, "MachineInteger"], arg + 1]FunctionCompile uses Typed annotations for compiling code:
cf = FunctionCompile[f]The CompiledCodeFunction evaluates with an argument that matches the type:
cf[10]If the type of an argument does not match the declared type, an error results:
cf[10.5]cf = FunctionCompile@Function[Typed[arg, "ListVector"::["String"]], AnyTrue[arg, StringLength[#] > 4&]
]The resulting compiled function has the type:
Information[cf, "Type"]The computation then proceeds as expected:
cf[{"ab", "cd", "ef", "abcde"}]A function type can be supplied as an argument to a compiled function:
cf = FunctionCompile@Function[{Typed[funArg, {"MachineInteger"} -> "MachineInteger"], Typed[n, "MachineInteger"]}, funArg[n]];
cfArg = FunctionCompile[Function[Typed[arg, "MachineInteger"], arg + 1]]The computation then proceeds as expected:
cf[cfArg, 10]Typed can also be used within FunctionDeclaration:
decl = FunctionDeclaration[
AddTwo, Typed[{"Integer64"} -> "Integer64"]@Function[arg, 2 + arg]
]The declaration is then supplied to FunctionCompile:
cf = FunctionCompile[decl, Function[Typed[arg, "Integer64"], AddTwo[arg]]]The compilation incorporates the declared function as expected:
cf[10]Properties & Relations (2)
When used in the parameter list of a pure function, Typed is effectively ignored in non-compiled evaluation:
Function[{Typed[x, "Real64"]}, x + 1]["two"]When used in the body of a pure function, Typed remains literal under ordinary Wolfram Language evaluation:
Function[{x}, x + Typed[1, "Real64"]]["two"]Typed is inert under ordinary evaluation:
Typed[x, "Boolean"]TypeHint, which can also be used in functions, evaluates to its first argument during normal evaluation:
TypeHint[x, "Boolean"]Possible Issues (1)
Use in Evaluated Code (1)
Typed can be used in the body of a function:
func = Function[{}, Typed[1, "UnsignedInteger8"]];
comp = FunctionCompile[func]When compiled, it is used to guide the type inferencing process:
comp[]However, when evaluated, Typed is treated as an inert expression:
func[]It is better to use TypeHint in the body of a function:
func = Function[{}, TypeHint[1, "UnsignedInteger8"]];
comp = FunctionCompile[func]When compiled, it is used to guide the type inferencing process:
comp[]However, when evaluated, TypeHint is stripped out:
func[]Tech Notes
Related Guides
History
Text
Wolfram Research (2019), Typed, Wolfram Language function, https://reference.wolfram.com/language/ref/Typed.html.
CMS
Wolfram Language. 2019. "Typed." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Typed.html.
APA
Wolfram Language. (2019). Typed. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Typed.html
BibTeX
@misc{reference.wolfram_2026_typed, author="Wolfram Research", title="{Typed}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/Typed.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_typed, organization={Wolfram Research}, title={Typed}, year={2019}, url={https://reference.wolfram.com/language/ref/Typed.html}, note=[Accessed: 13-June-2026]}