Damas-Hindley-Milner Algorithm W

(refer to the expected AST node layouts in the comments of types.js)

Here is also a simple C# version.