Skip to content

Revert "Update opaques.md" #11038

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

Merged
merged 1 commit into from
Jan 8, 2021
Merged

Conversation

mbloms
Copy link
Contributor

@mbloms mbloms commented Jan 8, 2021

Reverts #10976

This was not a typo.

The Access object defines three opaque type aliases:

  • Permission, representing a single permission,
  • Permissions, representing a set of permissions with the meaning "all of these permissions granted",
  • PermissionChoice, representing a set of permissions with the meaning "at least one of these permissions granted".

permissionSetX & permissionSetY is supposed to be the union of permissionSetX and permissionSetY, not the intersection of them.

It's also clear that def & (y: Permissions): Permissions = x | y was intentional from this text:

Also, the definition of ReadWrite must use |, even though an equivalent definition outside Access would use &.

What is meant by this is that the real method & would take precedent over the extension method &, so | must be called manually instead of & in the Access object.

The idea with this example is to show that it's useful that a single permission has the same representation as the equivalent singleton Permissions set or the equivalent PermissionChoice set.

If one wanted to, the subtyping relation could be changed to this:

//"All permissions in X granted" implies "At least one permission in X granted"
opaque type Permissions <: PermissionsChoice = Int
//At least one of these permissions granted
opaque type PermissionChoice = Int
//"A single permission granted" implies "All permissions in this singleton set granted"
opaque type Permission <: Permissions = Int

The example demos how opaque types behaves in many ways at the same time, perhaps even too much in too little text, hence why it's a bit confusing.

Copy link
Contributor

@b-studios b-studios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, when reviewing the PR I only looked at the changes without looking at the text so got it wrong as well.

@b-studios b-studios merged commit 2cf4dc4 into scala:master Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants