CompiledExpressionDeclaration[h,n]
represents a type for expressions of the form h[x1,x2,…,xn], suitable for use in compiled code.
CompiledExpressionDeclaration[h,{t1,t2,…}]
represents a type for expressions of the form h[x1,x2,…,xn], with xi having the type ti.
CompiledExpressionDeclaration[h"name",…]
names the declared type "name".
CompiledExpressionDeclaration[h"name"::[v1,v2,…],{t1,t2,…}]
represents a parameterized type with parameters labeled by v1,v2,….
CompiledExpressionDeclaration[h"name"::[v1,v2,…],cond,{t1,t2,…}]
asserts the condition cond on the type parameters.
CompiledExpressionDeclaration[…,test]
represents a type for any expression expr on which the compilable function test returns True.
CompiledExpressionDeclaration
CompiledExpressionDeclaration[h,n]
represents a type for expressions of the form h[x1,x2,…,xn], suitable for use in compiled code.
CompiledExpressionDeclaration[h,{t1,t2,…}]
represents a type for expressions of the form h[x1,x2,…,xn], with xi having the type ti.
CompiledExpressionDeclaration[h"name",…]
names the declared type "name".
CompiledExpressionDeclaration[h"name"::[v1,v2,…],{t1,t2,…}]
represents a parameterized type with parameters labeled by v1,v2,….
CompiledExpressionDeclaration[h"name"::[v1,v2,…],cond,{t1,t2,…}]
asserts the condition cond on the type parameters.
CompiledExpressionDeclaration[…,test]
represents a type for any expression expr on which the compilable function test returns True.
Details
- CompiledExpressionDeclaration is a symbolic representation of a declaration and does not evaluate on its own.
- CompiledExpressionDeclaration can be used inside of CompilerEnvironmentAppendTo and the first argument of functions like FunctionCompile.
- When no explicit type name is provided, SymbolName[h] is used.
- When argument types are specified, compiled expressions are internally stored as an efficient product type.
- When argument types are specified, CompiledExpressionDeclaration automatically defines functions including constructors Part and Head.
- When argument types are not specified, compiled expressions are internally stored with "InertExpression".
- When argument types are not specified, test[expr,ty] is used to check whether a given expression expr matches the compiled expression type ty.
Examples
open all close allBasic Examples (2)
Represent a declaration of a type representing expressions of the form foo[_Integer,_Real] but that internally stores the data in a product type:
dec = CompiledExpressionDeclaration[foo, {"Integer64", "Real64"}];Compile a function which instantiates and returns an object with the new type:
cf = FunctionCompile[dec, Function[{}, foo[3, 5.6]]]cf[]Represent a declaration of a type representing expressions with the head foo and length 2 and that internally stores the data in an expression:
dec = CompiledExpressionDeclaration[foo, Function[{expr, ty}, Length[expr] === 2]];Compile a function that takes foo as an argument and returns it unchanged:
cf = FunctionCompile[dec, Function[Typed[arg, "foo"], arg]]The function accepts expressions that have the specified structure:
cf[foo[1, 2]]But rejects expressions that do not have the specified structure:
cf[bar[1, 2, 3]]Scope (2)
A declaration of a type representing expressions with head foo and that takes any number in its first argument and a Boolean in its second argument:
dec = CompiledExpressionDeclaration[foo -> "foo"::[n], n∈"Numbers", {n, "Boolean"}];Compile a function that returns an object with that type:
cf = FunctionCompile[dec, Function[{}, foo[3.6, True]]]cf[]Note that the return type of the function is parameterized by the type of number that the foo takes in its first argument.
A declaration of a type representing expressions with head foo and that takes any two arguments:
dec = CompiledExpressionDeclaration[foo, 2];Compile a function that returns an object with that type:
cf = FunctionCompile[dec, Function[{}, foo[3, True]]]cf[]Note that the return type of the function is parameterized by the two argument types. This is equivalent to declaring a compiled expression that has unrestricted type variables in both arguments:
cf = FunctionCompile[{
CompiledExpressionDeclaration[foo -> "foo"::[t1, t2], {t1, t2}]
},
Function[{}, foo[3, True]]]cf[]Tech Notes
Related Guides
History
Text
Wolfram Research (2022), CompiledExpressionDeclaration, Wolfram Language function, https://reference.wolfram.com/language/ref/CompiledExpressionDeclaration.html.
CMS
Wolfram Language. 2022. "CompiledExpressionDeclaration." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CompiledExpressionDeclaration.html.
APA
Wolfram Language. (2022). CompiledExpressionDeclaration. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CompiledExpressionDeclaration.html
BibTeX
@misc{reference.wolfram_2026_compiledexpressiondeclaration, author="Wolfram Research", title="{CompiledExpressionDeclaration}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/CompiledExpressionDeclaration.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_compiledexpressiondeclaration, organization={Wolfram Research}, title={CompiledExpressionDeclaration}, year={2022}, url={https://reference.wolfram.com/language/ref/CompiledExpressionDeclaration.html}, note=[Accessed: 12-June-2026]}