Assuming you use some sort of an object to represent values, there
will probably be some type information there, saying wether the value
is a boolean, an int or a double. However, since you know the program
you are interpreting did type-check, you can allow yourself to skip
some checks (e.g. in the case of Java you can safely cast a generic
value object to a type specific subclass).
cheers,
Arnar
Exp annotExp (Env env, Exp exp) = typ := inferExp env exp return typed<typ>(exp)
As Aarne wrote later, you need to construct the values in the
interpreter with their particular type, but this information does not
have to come from the type checker (which would complicate things
somewhat). The choice of constructors is simply taken when you
interpret literal expressions. E.g.
evalExpr env (EInt x) = (env, VInt x)
(assuming evalExpr has the type Env -> Expr -> (Env, Value) and EInt
is the name of the Expr rule in your grammar for integer literals.)
cheers,
Arnar
Everything has been handed in with the student administration, so any day now.
cheers,
Arnar