Skip to content
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

Closed
wants to merge 6 commits into from
Closed

Types of types are unit types #151

wants to merge 6 commits into from

Conversation

josh11b
Copy link
Contributor

@josh11b josh11b commented Aug 26, 2020

Attempt to prove the claim that typeof(Int32) is a unit type.

@josh11b josh11b added WIP proposal A proposal labels Aug 26, 2020
@googlebot googlebot added the cla: yes PR meets CLA requirements according to bot. label Aug 26, 2020
@josh11b josh11b requested a review from a team August 27, 2020 23:47
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)
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

@josh11b josh11b Sep 2, 2020

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.

@zygoloid
Copy link
Contributor

zygoloid commented Sep 2, 2020

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, 1 and 1000000, or Int and Float) that are notionally related: there is some set of operations that applies to both. There exists a common type that both values inhabit. But there are also some operations that can be performed on one value but not the other -- in particular, conversion to some type that contains some of the values but not others: 1 as Int16 is valid but 1000000 as Int16 is not, Int as Integral is valid but Float as Integral is not.

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.

@jonmeow jonmeow marked this pull request as draft April 20, 2021 16:18
@jonmeow jonmeow removed the WIP label Apr 20, 2021
@github-actions
Copy link

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 inactive label.
This PR is labeled inactive because the last activity was over 90 days ago. This PR will be closed and archived after 14 additional days without activity.

@github-actions github-actions bot added the inactive Issues and PRs which have been inactive for at least 90 days. label Jul 31, 2021
@github-actions
Copy link

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.
This PR was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes PR meets CLA requirements according to bot. inactive Issues and PRs which have been inactive for at least 90 days. proposal deferred Decision made, proposal deferred proposal A proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants