-
Notifications
You must be signed in to change notification settings - Fork 13.3k
TRPL: Explain Bottom and Unit Types #25244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The unit type no longer exists, and ! is mentioned, though I forget where at the moment. |
Oh, okay. What is the type of Bottom is used in http://doc.rust-lang.org/nightly/book/lang-items.html but I couldn't find the word 'bottom' being used to describe a type in Wikipedia mentions Rust, by the way: https://en.wikipedia.org/wiki/Unit_type and https://en.wikipedia.org/wiki/Bottom_type |
@steveklabnik, never mind, I found it: Diverging functions |
I don't think ! Is technically a bottom type. The type of () is just a zero-sized or empty tuple, yes. It's not particularly surprising that Wikipedia is outdated, heh. We did have an express unit type before, it's just gone now. |
/cc @pnkfelix re bottom types |
The unit type was removed from the compiler implementation for convenience reasons but that doesn't mean we're not allowed to pretend it exists in user-facing terminology and documentation, including TRPL, if it's deemed beneficial for didactics. |
I feel very strongly that we are not allowed. Teaching something that doesn't actually exist isn't a good idea. |
Poor wording on my part. It does exist, it just has a different name (nullary tuple). This particular issue is obviously insignificant but on a meta level it seems like giving names to entities that aren't necessarily formally distinct, when such a simplification benefits the learning process of the student, is a valid thing to do in teaching, and is also quite common. |
I agree with @jakub- : I plan to continue referring to It has a special role in the language so special treatment is justifiable. |
There are several places where the reference doc mentions "unit" or "the unit type" with an associated link to the "Primitive types" section. Example: "If a Suggestion: add a sentence about it to the "Tuple types" section, and update these references to link there. The mention could be something like,
|
Should translations use an analog of the “unit type/value” term or just use “empty tuple” everywhere? |
Okay, so, after having some discussions with people, I understand where my historical confusion comes from. Ignoring that, however, I agree with @graue wrt how a patch for this should go. |
The book currently lacks any mention of these two special types:
!
, which denotes there is no type (this e.g. the type of a function that does not return) and()
, which is basically an empty tuple and thus a type with exactly one variant.@steveklabnik, I wanted to make a PR for this, but I wasn't sure where to add this. The "Primitive Types" chapter seems to cover the topic of types, but people read about
bool
,str
andi32
are probably not looking for type theory material…The text was updated successfully, but these errors were encountered: