Skip to content

Support M.[], M.(), M.{< >} and M.[| |].#144

Closed
yallop wants to merge 1 commit intoocaml:trunkfrom
yallop:empty-local-open-delimiters
Closed

Support M.[], M.(), M.{< >} and M.[| |].#144
yallop wants to merge 1 commit intoocaml:trunkfrom
yallop:empty-local-open-delimiters

Conversation

@yallop
Copy link
Copy Markdown
Member

@yallop yallop commented Feb 11, 2015

Fixes PR#635.

A small follow-up to PR#6054, which added support for the forms

M.[e1; e2; ... en]
M.[|e1; e2; ...; en|]
M.{l1=e1; l2=e2; ... ln=en}
M.{<e1; e2; ... en>}

This patch adds support for the empty cases:

M.[]
M.[||]
M.()
M.{<>}

The empty forms aren't particularly useful in themselves, of course, but the uniformity is convenient.

@damiendoligez
Copy link
Copy Markdown
Member

Looks good.

@Drup
Copy link
Copy Markdown
Contributor

Drup commented Feb 11, 2015

That would prevent introducing the dot notation for redefinitions of () and [].

@yallop
Copy link
Copy Markdown
Member Author

yallop commented Feb 11, 2015

I don't see why it would.

# module M = struct type t = () end;;
module M : sig type t = () end
# M.();;
- : M.t = M.()

@Drup
Copy link
Copy Markdown
Contributor

Drup commented Feb 11, 2015

Oh, so this patch actually implement the dot notations I was thinking of, nevermind then.

@yallop Shouldn't M.() and M.[] be constr_longident (instead of simple_expr) ? My intuition tells me they should behave like any constructor M.Foo, syntax wise.

@yallop
Copy link
Copy Markdown
Member Author

yallop commented Feb 11, 2015

I think an argument can be made for either constr_longident or simple_expr: M.[] is currently treated as a special case of M.[ exp; ... exp ] (which is a simple_expr), but it could equally well be treated as a variation of [] (which is a constr_longident).

@Drup
Copy link
Copy Markdown
Contributor

Drup commented Feb 11, 2015

except constr_longident is called inside simple_expr, so putting it inside constr_longident accepts more (valid, since they are accepted with []/()) form. Also, I argue that having M.[] in patterns is a good thing.

@yallop
Copy link
Copy Markdown
Member Author

yallop commented Feb 11, 2015

I don't see any reason to accept M.[] in patterns for the moment, since [] can't be redefined.

Thinking about this a bit more, the problem with updating constr_longident instead of simple_expr is that it breaks the local open semantics. As it is, M.[e] and M.[] have the same resolution behaviour: bring everything in M into scope, then resolve everything in the local environment. If we were to change constr_longident instead of simple_expr then M.[e] would continue to behave that way, but M.[] would fail unless M defined [].

So I think the patch is better as it is.

@Drup
Copy link
Copy Markdown
Contributor

Drup commented Feb 11, 2015

Thinking about this a bit more, the problem with updating constr_longident instead of simple_expr is that it breaks the local open semantics. As it is, M.[e] and M.[] have the same resolution behaviour: bring everything in M into scope, then resolve everything in the local environment. If we were to change constr_longident instead of simple_expr then M.[e] would continue to behave that way, but M.[] would fail unless M defined [].

Ok, that's a good argument, even if I personally think we should be allowed to redefined [] anyway.

@damiendoligez
Copy link
Copy Markdown
Member

Before you redefine anything, have a look at the discussion of PR#5936.

@gasche
Copy link
Copy Markdown
Member

gasche commented Apr 12, 2015

Merged in trunk, thanks.

I had one minor complaint with the patch: you wrote an excellent rationale for the change as your pull request text, but it was absent from the commit messages itself. I like good commit messages.

@gasche gasche closed this Apr 12, 2015
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Aug 3, 2017
Refactor domain interrupts and synchronisation
chambart pushed a commit to chambart/ocaml-1 that referenced this pull request Sep 9, 2021
* Refactor max_register_pressure (from upstream PR 9945)

* Fix i386 build
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Oct 5, 2021
* Refactor max_register_pressure (from upstream PR 9945)

* Fix i386 build
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
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.

4 participants