Typed[expr,type]
コンパイルやその他の目的のための指定された型であると仮定される式を表す.
Typed
コンパイル型のリスト »Typed[expr,type]
コンパイルやその他の目的のための指定された型であると仮定される式を表す.
詳細
- Function[{Typed[x1,type1], …}, …]を使って,コンパイルやその他の目的でFunctionオブジェクトが取る引数型を指定することができる.
- 次は,Typedがサポートする型である.
-
"name" 指定された名前のネイティブ型のオブジェクト {type1,type2,…}type typei型の引数を取って指定の型を返す関数 cons::[type1,type2,...] コンストラクタ cons を使って作られた複合型のオブジェクト - 次は,Typedがサポートするネイティブ型である.
-
"Boolean" ブール数 "ComplexReal64" IEEE倍精度実部と虚部の複素数 "Integer8" 8ビット符号付き整数 "Integer16" 16ビット符号付き整数 "Integer32" 32ビット符号付き整数 "Integer64" 64ビット符号付き整数 "Integer128" 128ビット符号付き整数 "MachineInteger" 機械サイズの符号付き整数 "Real32" IEEE単精度実数 "Real64" IEEE倍精度実数 "UnsignedInteger8" 8ビットの符号なし整数 "UnsignedInteger16" 16ビットの符号なし整数 "UnsignedInteger32" 32ビットの符号なし整数 "UnsignedInteger64" 64ビットの符号なし整数 "UnsignedInteger128" 128ビットの符号なし整数 "UnsignedMachineInteger" 機械精度符号なし整数
例題
すべて開く すべて閉じる例 (4)
Typedは,関数の引数型を指定する:
f = Function[Typed[arg, "MachineInteger"], arg + 1]FunctionCompileはコンパイルコードにTyped注釈を使う:
cf = FunctionCompile[f]CompiledCodeFunctionは型が一致する引数を使って評価する:
cf[10]cf[10.5]cf = FunctionCompile@Function[Typed[arg, "ListVector"::["String"]], AnyTrue[arg, StringLength[#] > 4&]
]Information[cf, "Type"]cf[{"ab", "cd", "ef", "abcde"}]関数型は,コンパイルされた関数の引数として使うことができる:
cf = FunctionCompile@Function[{Typed[funArg, {"MachineInteger"} -> "MachineInteger"], Typed[n, "MachineInteger"]}, funArg[n]];
cfArg = FunctionCompile[Function[Typed[arg, "MachineInteger"], arg + 1]]cf[cfArg, 10]TypedはFunctionDeclarationで使うこともできる:
decl = FunctionDeclaration[
AddTwo, Typed[{"Integer64"} -> "Integer64"]@Function[arg, 2 + arg]
]宣言はFunctionCompileに渡される:
cf = FunctionCompile[decl, Function[Typed[arg, "Integer64"], AddTwo[arg]]]cf[10]特性と関係 (2)
Typedは,純関数のパラメータリストで使用される場合は非コンパイル評価では実質的に無視される:
Function[{Typed[x, "Real64"]}, x + 1]["two"]Typedは,純関数の本体内で使用された場合は通常のWolfram言語の評価のもとでもリテラルのまま保持される:
Function[{x}, x + Typed[1, "Real64"]]["two"]Typed は,通常の評価のもとでは不活性である:
Typed[x, "Boolean"]TypeHintは関数内でも使用でき,通常の評価ではその第1引数に評価される:
TypeHint[x, "Boolean"]考えられる問題 (1)
評価されたコードで使用する (1)
Typedは関数本体で使用できる:
func = Function[{}, Typed[1, "UnsignedInteger8"]];
comp = FunctionCompile[func]comp[]しかし,Typedは評価されると不活性式として扱われる:
func[]関数本体ではTypeHintを使うほうがよい:
func = Function[{}, TypeHint[1, "UnsignedInteger8"]];
comp = FunctionCompile[func]comp[]しかし,TypeHintは評価されると取り除かれる:
func[]テクニカルノート
テキスト
Wolfram Research (2019), Typed, Wolfram言語関数, https://reference.wolfram.com/language/ref/Typed.html.
CMS
Wolfram Language. 2019. "Typed." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Typed.html.
APA
Wolfram Language. (2019). Typed. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Typed.html
BibTeX
@misc{reference.wolfram_2026_typed, author="Wolfram Research", title="{Typed}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/Typed.html}", note=[Accessed: 04-December-2026]}
BibLaTeX
@online{reference.wolfram_2026_typed, organization={Wolfram Research}, title={Typed}, year={2019}, url={https://reference.wolfram.com/language/ref/Typed.html}, note=[Accessed: 04-December-2026]}