TypeOf
TypeOf[expr]
gives the type of expr without evaluating it.
TypeOf[expr,decls]
uses declarations decls.
Details and Options
- TypeOf can be used in both interpreted and compiled programs.
- TypeOf uses the type inferencing system of the Wolfram Compiler.
- TypeOf only accepts expressions and types that can be compiled by the Wolfram Compiler.
- TypeOf can be used in interpreted code as a quick check whether compilation will work.
- TypeOf can be used in compiled code to determine the type of some part of the code.
- TypeOf can be used with TypeEvaluate to direct the type for a function declaration.
- TypeOf can take both Typed and declaration specifications such as FunctionDeclaration and TypeDeclaration.
Examples
open allclose allBasic Examples (6)
TypeOf is useful since it just determines the type of a function, giving an indication that compilation may work.
Find the type of an expression:
Find the type of an expression while specifying only the type of a subexpression:
Find the type of a function using a FunctionDeclaration:
Compile a program that contains TypeOf:
TypeOf is useful in polymorphic declarations written with ForAllType because the types of arguments are not known when the declaration is made:
TypeOf can be used with TypeEvaluate to determine the type in a declaration:
Scope (2)
Find the type of a program using arrays:
TypeOf does not evaluate its argument in compiled code, just as in evaluated code:
Properties & Relations (3)
TypeOf infers the type of its input without evaluating it:
TypeOf gives the return type of the CompiledCodeFunction generated by FunctionCompile but is much faster:
If TypeOf is unable to compile something, it issues a message that typically contains a button to show the source of the error:
Clicking the source button typically opens a user interface that can help to locate the error:
Possible Issues (3)
TypeOf can only infer the types of compilable programs:
TypeOf does not evaluate its argument, which leads to unintended consequences:
The argument of TypeOf may need explicit evaluation:
TypeOf only computes the type of its primary argument, so does not find errors in declarations:
FunctionCompile does a full compilation and can find errors in declarations:
Text
Wolfram Research (2022), TypeOf, Wolfram Language function, https://reference.wolfram.com/language/ref/TypeOf.html.
CMS
Wolfram Language. 2022. "TypeOf." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TypeOf.html.
APA
Wolfram Language. (2022). TypeOf. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TypeOf.html