なることを確認する(ちがったら例外) typecheck( ) typecheck( ) //=> "Boolean" C C T E if cond thn els typecheck( ) //=> ? E typecheck( ) //=> ? T "Boolean" なら OK 同じなら OK
(funcTy.tag !== "Func") throw "function type expected"; if (funcTy.params.length !== t.args.length) throw "wrong number of arguments"; for (let i = 0; i < t.args.length; i++) { const argTy = typecheck(t.args[i], tyEnv); if (!typeEq(argTy, funcTy.params[i].type)) throw "parameter type mismatch"; } return funcTy.retType; }
• function 文の後の式 の文脈では、変数 foo が参照できる typecheck( ,{…}) typecheck( ,{…, x: , foo: }) B number number => number x: number recFunc foo params body rest B R typecheck( ,{…, foo: }) R number => number B R