-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Generic across forms #5389
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
base: trunk
Are you sure you want to change the base?
Generic across forms #5389
Conversation
|
||
In addition, there are a number of outstanding problems in Carbon that arise | ||
from a construct requiring some specification of aspects in a binding when it | ||
should instead to a |
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.
Looks like something's missing here.
- `Core.ValSelf`, `Cor.RefSelf`, and `Core.VarSelf` that take a `Core.Form` | ||
facet type and return an ordinary `type` facet type with the specified | ||
category used for `Self`. | ||
- `Core.Form where .type = T` which gives a form facet type that matches any |
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.
This seems like it follows from what's already been said about Core.Form
and .type
, rather than being a separate feature introduced by this proposal. Am I missing something?
- An `impl` may use `anchor` or `exact` to limit the conversions allowed, | ||
which can be needed to satisfy the orphan rule. | ||
- Implied constraints are not added for variant parameters. | ||
- When normally we would for a facets of an interface, if that interface |
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'm having a hard time parsing this sentence -- I feel like maybe there's a missing verb after "would", and "a facets" is clearly a typo but I'm not sure what the correct version is.
The [compound form approach we settled on](#compound-form-values) had the | ||
advantage of supporting all the composition we wanted without needing any | ||
dedicated syntax. It is a bit verbose, but that is perhaps acceptable given that |
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.
Why can't we instead say that form()
can contain anything that can appear in a ->?
return form, e.g. form((var i32, ref f64, formof(7)))
? That requires no more dedicated syntax than the current proposal, and it would make the language more consistent, as well as making compound form literals less verbose.
With this approach, the call to `F` would convert the reference expression `a` | ||
into a value before overload resolution and select "Overload V." | ||
|
||
We instead decided that `ref` on an argument only affects deduction. In this |
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.
We instead decided that `ref` on an argument only affects deduction. In this | |
We instead decided that `ref` on an argument only affects deduction, because this | |
minimizes the divergence between function calls and other forms of pattern maching. In this |
Feel free to take or leave that particular suggestion, but it would be good to give some indication of why we chose this.
This allows us to address the use case of creating a binding that is | ||
[referentially transparent](https://en.wikipedia.org/wiki/Referential_transparency), | ||
as considered in leads issues | ||
[#996](https://github.com/carbon-language/carbon-lang/issues/996) and | ||
[#1371](https://github.com/carbon-language/carbon-lang/issues/1371). For |
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.
If I understand correctly, the binding itself isn't quite referentially transparent, because if y
is an initializing expression, x
will be a reference expression. Instead, ~x
is referentially transparent (given the assumptions you make elsewhere about the semantics of ~
). It's probably worth saying so explicitly.
Co-authored-by: Geoff Romer <[email protected]>
Co-authored-by: Geoff Romer <[email protected]>
Co-authored-by: Geoff Romer <[email protected]>
We propose:
Core.Form
whose values describe the form (category, phase, and so on) of parameters or returns in the signature of functions.form(
...)
literal syntax for writing values of these form types.&
.:?
binding and->?
return syntax parameterized by a form value.Core.CallPrimitive
, that allow control over the form of the parameters and return.call(
...)
syntax for concisely and naturally writing facet types of theCore.CallPrimitive
interface.Core.Form
values in interface arguments and associated constants, when specified by the interface, replacing the existing mechanism whereimpl
s uselike
to allow implicit conversions in arguments.Together these changes will allow:
Core.CallPrimitive
form interface;Core.Call
andCore.AddWidth
with named constraints that use types instead of forms;alias
, along with a shorthandusing
;