Add short syntax for dependent functor types #12828
Merged
nojb merged 3 commits intoocaml:trunkfrom Jul 3, 2024
Merged
Conversation
Contributor
|
This PR
In short, it looks like an excellent change, I'm wholly in favour! |
gasche
reviewed
Dec 19, 2023
Member
|
I don't personally see functor types enough to perceive a real need for this syntactic sugar, but I see no harm with it either, and it is consistent with the previous shortcut syntaxes we introduced as @yallop recalled. I am tempted to vote in favor, unless someone comes with a counter-argument. |
3a64baf to
9249b3c
Compare
Member
Author
|
I've rebased to resolve conflicts, and credited @nojb as reviewer. |
Contributor
|
This is a big change in terms of modified outputs, but I agree this looks nicer. The |
Contributor
9249b3c to
331d663
Compare
331d663 to
2869c4a
Compare
Member
Author
|
I've fixed the conflict, incorporated @gasche's proposed change (which I'd somehow completely missed; sorry!) and credited him as a reviewer. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief summary
This PR adds a concise variant of functor type syntax. In brief, it allows (but does not require) the keyword
functorto be omitted in functor types (but not in functor terms).In other words, the current functor syntax looks like this:
and this PR extends the syntax to also allow writing this:
The new syntax is commonly used in dependently-typed languages such as Agda and Idris.
Previous episodes
The PR is the latest installment in an occasional series of functor type syntax simplifications. Previous episodes:
Simplify functor sig types #16 (OCaml 4.02.0) added shorter syntax for functor signatures, allowing
-> functorto be omitted for type parameters after the first:Before:
After:
Short functor type syntax #42 (OCaml 4.03.0) added shorter syntax for non-dependent functor parameters, allowing parameter names to be omitted
:
Before:
After:
Add short syntax for generative functor types: () -> ... #11694 (OCaml 5.1.0) added similarly short syntax for generative functor types:
Before:
After:
Motivation
Functor types occur occasionally in programs, but appear quite often in error messages and top-level printing, where the full syntax can make them rather difficult to read. Here is a fairly typical example from the test suite:
After this PR the message is shorter:
Omitting
functormakes the error message significantly shorter (15 lines rather than 23) because it allows the parameter types to fit on a single line.