I am developing a interpreter of a functional programming language, which uses Hindley-Milner type system.
The question is, where should type errors occur(be detected)?
For example, if I apply Integer
type value to a function that has type Bool -> Integer
, this is obviously a type error. Can type inferer always detect this?
My speculation is that, the type inferer doesn't always fully know the types of expressions, i.e. in process of inference. Therefore some errors detected by the type inferer would be wrong, or some errors would not be detected.
However, expression evaluator should detect type errors properly, because the evaluator fully knows the types of expressions.
If the type inferer cannot detect type errors correctly, then how statically typed interpreted languages such as OCaml, process static type error checking?