I have found myself wanting to do something like the following on several occasions:Future<void> someAsyncActionWhichDoesNotProduceAValue();
Currently you would have to do:Future
Future<Null> // I assume this works, haven't tested
neither of which capture the intent.Also, it's weird that I can use it as the return value of a getter, but not as the type of a field:void get foo(); // legalfinal void foo; // illegalWould it make sense to make "void" just a normal type in the core lib, just like "Dynamic" ?
It should probably still remain reserved for now, but it would open it up to being unreserved at some point in the future.Cheers,
Sean Eagan
Normal types denote (roughly) a set of values. Void indicates the absence of a value. We could view it as the empty set.
Then it would be legal to have a variable have type void - logically it would be a variable that never holds a value. But in fact, no such variable exists in Dart - there is always something there, if only null.Of course, Dart doesn't have functions that do not return a value. They will return null if nothing else. We use void as marker for the type system to help catch misuse of functions that are not intended to return a value (i.e., used only for side effects). If we allowed wider use of void, we would be supposedly marking variables that are not intended to be used. This is useless, but more regular.
On Thu, Feb 16, 2012 at 4:06 PM, Gilad Bracha <gbr...@google.com> wrote:Normal types denote (roughly) a set of values. Void indicates the absence of a value. We could view it as the empty set.
Isn't void in Dart right now closer to Unit than to the bottom type you're describing here? I'm actually not sure what the difference between Null and Void is in Dart, actually, so maybe there's a distinction I'm missing.
Then it would be legal to have a variable have type void - logically it would be a variable that never holds a value. But in fact, no such variable exists in Dart - there is always something there, if only null.Of course, Dart doesn't have functions that do not return a value. They will return null if nothing else. We use void as marker for the type system to help catch misuse of functions that are not intended to return a value (i.e., used only for side effects). If we allowed wider use of void, we would be supposedly marking variables that are not intended to be used. This is useless, but more regular.It's not entirely useless, though. Void has its uses in Java (with generics) so many of those would likely apply to Dart too, I think. (Of course, whether or not we should care enough about generics in Dart to make an issue of that is an open question. :) )
- bob