5 ms·
The problem with void is that it's not a real type in C.
by the_mitsuhiko 12y ago
The problem with void is that it's not a real type in C.
- SideburnsOfDoom 12y agoYes, totally. The same in java and c# too. That's why I said void is "more or less like a type" and asked about "unit" as a "first class void" - i.e. a "void" that is a real type that works like other types.
- mercurial 12y agoWell, in Java you have http://docs.oracle.com/javase/7/docs/api/java/lang/Void.html http://docs.oracle.com/javase/7/docs/api/java/lang/Void.html Not exactly first-class but useful at times.
- jeremyjh 12y agoNull is not a type either, and you cannot reference it in a definition. I think void is a closer match.
- AaronFriel 12y agoAs someone else describes, void is the "uninhabited" type, i.e.: it cannot be created. Void is a way of indicating the absence of valid output. I think null is wrong too, because it references the fact that in most languages, types are a sum type of "all possible valid inputs" plus "null". Rust avoids null and has no null pointers unless you use unsafe code. Unit means "there is precisely one instance of this type". It is the unitary type.
- stonemetal 12y agoFirst you have to say if you are talking about () the type or () the value. () the type is fairly close to void in meaning. () the value is fairly close to null in meaning. Thus both comparisons are accurate, which is applicable depends on which () you are referring to. While your post is correct for () the type, if I consider () the value, your post could be transformed without loss of accuracy to: Void is not a value either, and you cannot return it from a function. I think null is a closer match. Value or type neither half is the whole story.
- bjz_ 12y agoI guess you could argue that 'null' refers to the '1' in a sum type 'T + 1'. I still think 'unit' is the most precise term though, especially seeing as Rust doesn't have structural sum types. `None` is the closest we get to null.