0

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?

suhdonghwi
  • 955
  • 1
  • 7
  • 20
  • 3
    Types are properties of the syntactic structure of the code. They don't exist at runtime, so I'm not sure why you think the evaluator can detect type errors (or why you think the type checker can't). – melpomene Mar 16 '18 at 14:59
  • @melpomene You are right. I am definitely confusing the concept of type. Thank you very much. – suhdonghwi Mar 17 '18 at 02:47

1 Answers1

0

... a type error. Can type inferer always detect this?

If your type inference is sound, then yes, it should always detect an error.

With Hindley-Milner type system, in particular, the algorithm relies on unification in order to find a principal type. In the case there's none, you'll end up with an unification error.

Leandro T. C. Melo
  • 3,974
  • 22
  • 22