2 ms·
> C has type inference! This is only one-way type deduction (similar to C++ `auto` keyword) which isn't really proper two-way type inference. It just copies th
by exDM69 10y ago
> C has type inference!
This is only one-way type deduction (similar to C++ `auto` keyword) which isn't really proper two-way type inference. It just copies the type of the right hand side to the left hand side.
E.g. given the following code:
x = less_than(a, b) ? (a+1) : b;
A proper type inference algorithm can deduce the types of less_than ((int, int) -> bool) and a (int because a+1) and b (int because it must match the other side of the conditional) and x (int). C++ auto could only defer the type of x given the types of less_than, a and b.
And by "proper type inference" I mean the text book Hindley-Milner unification algorithm from the 1970's, not a more modern variant with traits or type classes and whatnot.