-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Summary of issue:
Should we have a syntactic shorthand for Core.Optional(T)
? This type will come up frequently in interop scenarios, as C++'s T*
is expected to map into Core.Optional(T*)
in Carbon.
Details:
We brainstormed on this during the 2025-07 Carbon summit, but didn't come to a definitive conclusion.
Leading options seem to be:
- Postfix
?
, matching postfix*
for pointers, so C++T*
becomes CarbonT*?
. This then needs a solution that's not postfix?
for a "try" operator. - Prefix
?
, leaving postfix?
for a "try" operator. If we do this, we would likely want to make*
for pointers prefix instead. - A keyword, perhaps
opt
, either prefix or postfix, perhaps with parens:opt T*
orT* opt
oropt(T*)
.
Any other information that you want to share?
For a "try" operator, we've also been considering postfix .try
, which would leave syntactic space for postfix ?
as a type operator.
Switching to prefix *
and ?
for types, and postfix *
and ?
for expressions, would allow us to provide a more consistent operator set with fewer parentheses required, by making ~all of our value-level unary operators postfix. For example, p->x
becomes p*.x
, and *(*p)->y
becomes p**.y*
. But this would cost us a lot of our C++ familiarity budget, probably more than we have for Carbon in total.