What exactly are you calling &quot;type inference&quot;? It cannot be ML-like type reconstruction, because doing that requires either whole program analysis or a prohibition from interacting with untyped code.