Local exceptions (without the optimization)#301
Conversation
|
FTR, I'm strongly in favour of the language change, but I don't feel qualified to review the implementation in detail. |
Including for 4.03? |
We don't have a good consensus yet. What are the drawbacks of delaying it to 4.04? |
Just extra work to maintain the list of active open PR and go back to it later. I don't think it would be technically difficult to maintain the branch synchronized with trunk. |
People using old versions of OCaml will get even less chance to use this new syntax before dying of old age? 😎 |
7228e9f to
d8979d7
Compare
|
Rebased to trunk. From the comments above, @damiendoligez is strongly in favor, and I suspect @yakobowski as well. Is anyone opposed to merging to trunk? |
|
IIRC, the only opposition was from @lefessan, everyone else liked it. Can you find someone to review the code? |
|
@garrigue Do you think you could have a look at the type-checking part of this PR? (This is less than 10 lines, the rest is syntactic boilerplate or moving code around.) |
|
This looks fine to me. But some tests would help confidence. |
726b5a7 to
c7df852
Compare
c7df852 to
43f90e9
Compare
|
Now complete with a non-regression test, an entry in Changes and in the manual. |
Local exceptions (without the optimization)
This is a stripped down version of #260. Here I only propose to add local exception definitions, with no specific compilation (which can come later or not).
Local exceptions should be encouraged, since they document a more limited scope, which helps reasoning about the code and avoid subtle bug when higher-order function use a generic exception (such as Exit) for their internal control flow but can easily get confused if they call unknown function which could also raise the same exception.
Moreover, now that it is no longer allowed to define multiple exceptions with the same name in a given structure, it becomes even more important not to pollute the global scope.
There is of course a work-around for encoding local exceptions with local modules, but it's syntactically heavier (two names need to be invented) and less efficient (unless more optimization are added). People would more be likely to use global exceptions if we don't provide something lighter than this encoding.
See https://blogs.janestreet.com/a-universal-type/ for some fun use of (previously encoded) local exceptions that would benefit from this feature:
Note: the grammar has been massaged a little bit to avoid a conflict with
exceptionpatterns:As a result, exception patterns are now disallowed in let bindings. They were rejected by the type-checker anyway.