Type Checking, Coercion, and Inference
When a binary operator is reduced, as in our binop program, it is necessary to check the types of the arguments, possibly to coerce an argument to the correct type, and to infer the result type.
Suppose that X is real and I is integer.
Op Arg1 Arg2 Op New Arg1 New Arg2 Result
+ X X + X X real
+ I I + I I integer
+ I X + (float I) X real
:= I X := I (fix X) integer
< I X < (float I) X boolean
The result type is stored in the operator token.