OperationDeclaration
OperationDeclaration[type,op,typedfun]
declares a typed function to be used for the operation op of type.
Details
- OperationDeclaration is a symbolic representation of a declaration and does not evaluate on its own.
- The typed function in OperationDeclaration can be of the form Typed[{t1,t2,…}tout]@Function[{x1,x2,…},body].
- Any operations declared for a type in a TypeDeclaration will need an OperationDeclaration for the type to be used.
- The type in OperationDeclaration can be written polymorphically using ForAllType.
- OperationDeclaration avoids the need to make up a name for a function used as an operation.
Examples
Basic Examples (1)
A declaration of a product type with one operation:
A declaration of the operation:
Compile a function to create an instance of the type and another to call the "Increment" operation:
Call the "Increment" operation; the old value of 0 is returned:
Call the "Increment" operation again; now the old value is 1:
Text
Wolfram Research (2024), OperationDeclaration, Wolfram Language function, https://reference.wolfram.com/language/ref/OperationDeclaration.html.
CMS
Wolfram Language. 2024. "OperationDeclaration." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/OperationDeclaration.html.
APA
Wolfram Language. (2024). OperationDeclaration. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/OperationDeclaration.html