Typed[expr,type]

represents an expression that should be assumed to be of a specified type for compilation and other purposes.

Details

Examples

Basic Examples  (1)

Typed can be used to mark the suggested type of function arguments:

In[1]:=
Click for copyable input
Out[1]=

For computation in the Wolfram Engine the use of Typed is advisory:

In[2]:=
Click for copyable input
Out[2]=

FunctionCompile uses Typed for inferencing the types of code:

In[3]:=
Click for copyable input
Out[3]=

If the argument of a CompiledCodeFunction matches the declared type, the computation proceeds:

In[4]:=
Click for copyable input
Out[4]=

If the type of an argument does not match the declared type, an error results:

In[5]:=
Click for copyable input
Out[5]=
Introduced in 2019
(12.0)