Skip to content

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

Closed
killercup opened this issue May 9, 2015 · 12 comments
Closed

TRPL: Explain Bottom and Unit Types #25244

killercup opened this issue May 9, 2015 · 12 comments
Labels
A-type-system Area: Type system

Comments

@killercup
Copy link
Member

The book currently lacks any mention of these two special types:

  • The bottom type, !, which denotes there is no type (this e.g. the type of a function that does not return) and
  • the unit type, (), 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 and i32 are probably not looking for type theory material…

@killercup killercup changed the title TRPL: Explain Special Bottom and Unit Types TRPL: Explain Bottom and Unit Types May 9, 2015
@steveklabnik
Copy link
Member

The unit type no longer exists, and ! is mentioned, though I forget where at the moment.

@killercup
Copy link
Member Author

Oh, okay. What is the type of () and how should I pronounce it? Empty tuple?

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 src/doc/. Do we call it something else?

Wikipedia mentions Rust, by the way: https://en.wikipedia.org/wiki/Unit_type and https://en.wikipedia.org/wiki/Bottom_type

@killercup
Copy link
Member Author

@steveklabnik, never mind, I found it: Diverging functions

@steveklabnik
Copy link
Member

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.

@steveklabnik
Copy link
Member

/cc @pnkfelix re bottom types

@ghost
Copy link

ghost commented May 10, 2015

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.

@steveklabnik
Copy link
Member

that doesn't mean we're not allowed to pretend it exists

I feel very strongly that we are not allowed. Teaching something that doesn't actually exist isn't a good idea.

@steveklabnik steveklabnik added A-type-system Area: Type system A-docs labels May 10, 2015
@ghost
Copy link

ghost commented May 10, 2015

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.

@pnkfelix
Copy link
Member

I agree with @jakub- : I plan to continue referring to () as "unit", even if it's just a short hand for "empty tuple". (See also discussion here: #24738 (comment) )

It has a special role in the language so special treatment is justifiable.

@graue
Copy link

graue commented May 16, 2015

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 main function is present, its return type must be unit" in section 5. However, nothing in the "Primitive types" section mentions the unit or empty tuple type.

Suggestion: add a sentence about it to the "Tuple types" section, and update these references to link there. The mention could be something like,

For historical reasons and convenience, the tuple type with no elements (()) is sometimes called "unit".

@suhr
Copy link

suhr commented May 19, 2015

Should translations use an analog of the “unit type/value” term or just use “empty tuple” everywhere?

@steveklabnik
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

5 participants