-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Types of types are unit types #151
Conversation
implementation for an existing interface `Bar` for `Foo` at the same time. | ||
Similarly, if I define a new interface `Baz`, I can define implementations for | ||
existing types like `Int32` of `Baz` with `Baz`. See | ||
[the generics proposal](https://github.com/josh11b/carbon-lang/blob/generics-docs/docs/design/generics/facet-type-types.md#implementing-interfaces) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you link to this via the pull request, assuming there is a pull request for this branch already? It seems a little unusual for our design to link directly to your repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to, but I haven't found a URL that will give the latest version of the file, just the one associated with a particular commit.
[the generics proposal](https://github.com/josh11b/carbon-lang/blob/generics-docs/docs/design/generics/facet-type-types.md#implementing-interfaces) | ||
for details. | ||
|
||
A [unit type](https://en.wikipedia.org/wiki/Unit_type) is a type with a single |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if "singleton types" is a better term for what is meant here.
In a programming language there is just one "unit type".
But I think you want one of these for Int32 another another for Int64.
This use matches the meaning of singleton types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are likely correct, I'm not very familiar with common usage here, I was just using Wikipedia as the source of truth. https://en.wikipedia.org/wiki/Unit_type says:
The carrier (underlying set) associated with a unit type can be any singleton set. There is an isomorphism between any two such sets, so it is customary to talk about the unit type and ignore the details of its value.
I don't really understand the difference here between unit and singleton types though -- presumably this argument about being isomorphic applies equally well to singleton types. Is it just that you say "unit type" when you don't care about the unique value, making them the same?
I just did some searching and it appears while this matches the usage of "singleton type" in https://typesandkinds.wordpress.com/tag/singletons/, in https://en.wikipedia.org/wiki/Scala_(programming_language) "singleton type" seems to refer to a type with a single instance instead of a single value, matching https://en.wikipedia.org/wiki/Singleton_pattern instead of https://en.wikipedia.org/wiki/Singleton_(mathematics) . In the case of this document (and the Haskell case), the value is immutable and so the difference between values and instances is too small to concern us, which is an argument for making the change.
Reflecting more on this: the situation here seems exactly analogous to the argument made in #144 that numeric literals should have singleton types. In both cases, I think the argument goes like this: We have multiple different values (eg, I think we should have a consistent answer here, or a rationale for why we don't want a consistent answer. Either the type of the value (and not the value itself) should indicate which operations can be performed in all cases (in which case both literals and types should inhabit singleton types -- suggesting we accept both this and the broad direction of #144), or we accept that some operations can be predicated on the values of their operands, not only on their types, in which case the argument presented here does not hold. |
We triage inactive PRs and issues in order to make it easier to find active work. If this PR should remain active, please comment or remove the |
We triage inactive PRs and issues in order to make it easier to find active work. If this PR should remain active or becomes active again, please reopen it. |
Attempt to prove the claim that
typeof(Int32)
is a unit type.