% encoding type judgments % This definition is from chapter 33 of _Programming languages: application % and interpretation_, by Shriram Krishnamurthi. type(_, numConst, num). type(_, boolConst, bool). type(TEnv, if(Test, Then, Else), Tau) :- type(TEnv, Test, bool), type(TEnv, Then, Tau), type(TEnv, Else, Tau). type([bind(V, Tau) | _], var(V), Tau). type([bind(_, _) | TEnvRest], var(V), Tau) :- type(TEnvRest, var(V), Tau). type(TEnv, fun(Var, Body), arrow(Tau1, Tau2)) :- type([bind(Var, Tau1) | TEnv], Body, Tau2). type(TEnv, app(Fun, Arg), Tau2) :- type(TEnv, Fun, arrow(Tau1, Tau2)), type(TEnv, Arg, Tau1).