-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Restrict local open in constructor argument types #12343
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
Restrict local open in constructor argument types #12343
Conversation
end | ||
module StaticVersion = struct | ||
let require_20210419 = () | ||
let require_20220210 = () |
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 we are increasing the menhir version, shouldn't we move to the last released version?
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.
In my book, any move to a more recent version is fine.
parsing/parser.mly
Outdated
| atomic_type_without_open | ||
%prec below_HASH | ||
{ Pcstr_tuple [$1] } | ||
| ty = atomic_type STAR tys = inline_separated_nonempty_llist(STAR, atomic_type) |
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.
Remark: we could also disallow Foo of M.( x ) * N.( y )
to make it less surprising than Foo of M.(x)
is a syntax error.
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.
Hmm, or maybe it would be possible to allow Foo of M.(x)
. I will try that and come back to confirm that it is hell.
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 argue that having Foo of M.(x -> y)
allowed but not Foo of M.( x * y)
would not be an improvement in term of the readability of the grammar.
Suggested-by: Florian Angeletti <[email protected]>
On a suggestion by @Octachron, local open is now systematically disallowed in constructor arguments for consistency: the change proposed by @let-def would allow |
Personally, I'm happy with allowing |
I don't necessarily disagree. On the other hand, I see the following arguments in favor of restricting:
|
if that's the case, how would you express multiple constructor args with a local open? |
@hyphenrf note that there isn't currently a syntax to allow a local open around several arguments. (And I'm quite sure that it would be a bad idea to use One can of course use open struct
open M
type t = ...
end at the level of one or several structure items. |
I don't think it matters if it's not possible to express that with a single local open; there are lots of things local opens can't do. I think it's more important to have a uniform rule, like " |
I would argue that rule is respected either way here, as the debate is really about whether the argument to a constructor is a single type expression or a sequence of type expressions separated by *. I think it is the latter hence why I think it should be an error, but the other position is also consistent. |
Disallowing |
To recap, there are three choices:
I find (1) and (3) both conceptually simpler than (2), and the grammar is also simpler. In all cases |
I think that it may now too late to improve on this, local open in types has shipped without it and we haven't managed to build a consensus to restrict it here. Closing. |
Forbid
type t = Foo of M.(bar * baz)
which could be understood as two separate constructor argumentsM.bar
andM.baz
or a single tuple type.See #12044 (comment) -- thanks are due to @hypenrf for the report and @let-def for the implementation.