views:

299

answers:

2

What are the limits of type inference? Which type systems have no general inference algorithm?

+3  A: 

A value-dependent-type system (Or in short, dependent type system) can describe types that say things like: "At evaluation time (runtime), the value of this variable will always be equal to the value of that variable, which is computed with a different evaluation process". Automatically deducing this type from the code entails automatic proofs of theorems. If the set of theorems you can express is restricted to those automatically provable, that would not be a problem, but in the case of dependently-typed languages, this is generally not the case.

So dependently typed systems cannot have general (and complete) type inference.

I am sure someone can provide a moral formal and complete answer...

Peaker
+4  A: 

Joe Wells showed that type inference is undecidable for System F, which is the most basic polymorphic lambda calculus, independently discovered by Girard and Reynolds. This is the most important result showing the limits of type inference.

Here's an important problem that is still open: what is the best way to integrate Generalized Algebraic Data Types into Hindley-Milner type inference? Every year Simon Peyton Jones comes up with a new answers, which is supposedly better than the previous year's answer. I haven't read the March 2009 version and so can't say if I believe it will be definitive.

Norman Ramsey
So Algorithm W covers the largest possible subset of System F which is decidable?
ott
@ott: I'm not a pointy-headed type theorist, but I'd bet my |- symbol that System F has multiple, incomparable decidable subsets. Not to mention the possibility of extensions (GADTs, equality constraints, qualified types). It's full employment for the pointy-headed crowd :-)
Norman Ramsey
@Norman Ramsey: Interesting. I don't know if type theorists are pointy-headed, but the papers I saw seem to be really far from reality and I don't know if type theory will become mainstream and widely accepted; you still have to learn ML to even understand the basics.
ott