|
Your example, void foo() {
auto items = {1,2,3,4};
return;
}
is the case of poorly designed syntax, in a truly Hindley-Milner system there is
no expression which doesn't have a type. Now, we could add some syntax that
screws that up, say: let v = I-HAVE-AN-AMBIGUOUS-TYPE in 0
But that's rather silly, isn't it? If a value isn't used then I would,
personally, like my language to optimize it away. So why not ditch such silly
syntax?This is part of why I said that the foundations of C++ are too far-gone. And this syntax isn't necessary to save on typing. In a language that supported
syntactic macros (such as Scheme or Racket) we could write something like: auto items = my-vector-syntax(1,2,3,4);
which expands to something like: auto items;
items.push_back(1);
items.push_back(2);
items.push_back(3);
items.push_back(4);
If you're interested in true syntactic macros for non-sexp languages (though I
do suggest getting over the parentheses, my color settings make them nearly
indistinguishable from the background) look at Rust [1].Actually, Rust also has type inference [2]. Hell, stop programming in C++ and start using Rust! [3] [1] http://dl.rust-lang.org/doc/tutorial-macros.html
[2] http://dl.rust-lang.org/doc/0.4/rust.html#type-system
[3] http://www.rust-lang.org/ |