Programming languages ββwith some Hindley-Milner type output option can easily infer the type of expressions, such as
let rec fix f x = f (fix f) x
whereas the output of the return type in C ++ 1y is not executed for the following:
int main() {
auto fix =
[&](auto f) {
return [&](auto x) {
return f(fix(f))(x);
};
};
return 0;
}
I tried this with clang 3.5 and the command
clang++ -std=c++1y fix.cc
and i get
fix.cc:7:18: error: variable 'fix' declared with 'auto' type cannot appear in its
own initializer
return f(fix(f))(x);
What is missing in C ++ type output, which prohibits the use of a variable in its own initializer, when the return type must be inferred? What can I do to get around this problem, and even better, what can we do to fix it in the language?
source
share