OperationDeclaration[type,op,typedfun]
type の操作 op に使う型付き関数を宣言する.
OperationDeclaration
OperationDeclaration[type,op,typedfun]
type の操作 op に使う型付き関数を宣言する.
詳細
- OperationDeclarationは,宣言の記号表現であり単独では評価しない.
- OperationDeclarationの型付き関数は,Typed[{t1,t2,…}tout]@Function[{x1,x2,…},body]の形式でよい.
- TypeDeclarationで型について宣言された操作はどれも,使用される型についてのOperationDeclarationが必要である.
- OperationDeclarationの型は,ForAllTypeを使って多様な形で書くことができる.
- OperationDeclarationは使用すると,操作として使われる関数に命名する必要がなくなる.
例題
例 (1)
dec1 = TypeDeclaration["Product", "SimpleValue", <|"value" -> "MachineInteger"|>, "Operations" -> {"Increment"}, "AbstractTypes" -> {"DataStructures"}];dec2 = OperationDeclaration["SimpleValue", "Increment", Typed[{"SimpleValue"} -> "MachineInteger"]@Function[{arg},
arg["value"]++
]];型の例を作成する関数と"Increment" 操作を呼び出す関数をコンパイルする:
funs = FunctionCompile[{dec1, dec2}, <|"create" -> Function[{}, CreateTypeInstance["SimpleValue", <|"value" -> 0|>]],
"increment" -> Function[{Typed[ arg, "SimpleValue"]}, arg["Increment"]]
|>]obj = funs["create"][];"Increment"操作を呼び出す.0というもとの値が返される:
funs["increment"][obj]"Increment"操作を再度呼び出す.今回は1という新しい値が返される:
funs["increment"][obj]テクニカルノート
関連するガイド
テキスト
Wolfram Research (2024), OperationDeclaration, Wolfram言語関数, 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
BibTeX
@misc{reference.wolfram_2026_operationdeclaration, author="Wolfram Research", title="{OperationDeclaration}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/OperationDeclaration.html}", note=[Accessed: 04-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_operationdeclaration, organization={Wolfram Research}, title={OperationDeclaration}, year={2024}, url={https://reference.wolfram.com/language/ref/OperationDeclaration.html}, note=[Accessed: 04-November-2026]}