Skip to content
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

manual: document exception A | exception B #2187

Merged
merged 1 commit into from Dec 10, 2018

Conversation

Projects
None yet
4 participants
@Octachron
Copy link
Contributor

commented Dec 7, 2018

This is a small documentation follow-up for #1568 (exception pattern under or-patterns) .

This PR adds an example of such pattern in the tutorial and, more importantly, replaces the current example of invalid exception pattern with Some (exception A) .

I have also updated the grammar description to directly mention exception patterns under or-patterns.

cc @trefis @pmetzger

@Octachron Octachron force-pushed the Octachron:exception_match_doc branch from d1deeca to dfe0ab0 Dec 7, 2018

@yallop

This comment has been minimized.

Copy link
Member

commented Dec 7, 2018

The case where both sides of the or-pattern are exception patterns is not especially interesting, since exception p | exception q can usually (or perhaps always) be rewritten exception (p|q).

The case that's really worth documenting is where one side is an exception pattern and the other a value pattern:

let find x l =
   match List.assoc x l with
    | None | exception Not_found -> None
    | Some _ as v -> v

@Octachron Octachron force-pushed the Octachron:exception_match_doc branch from dfe0ab0 to dd0dca2 Dec 7, 2018

@Octachron

This comment has been minimized.

Copy link
Contributor Author

commented Dec 7, 2018

You are right, this makes a much better example.

together,
\begin{caml_example}{toplevel}
let find x l =
match List.assoc_opt x l with

This comment has been minimized.

Copy link
@yallop

yallop Dec 7, 2018

Member

List.assoc_opt won't raise Not_found

This comment has been minimized.

Copy link
@Octachron

Octachron Dec 7, 2018

Author Contributor

Indeed, I updated and renamed the function.

@Octachron Octachron force-pushed the Octachron:exception_match_doc branch 2 times, most recently from 685eed9 to 06553eb Dec 7, 2018

@yallop

yallop approved these changes Dec 7, 2018

@pmetzger

This comment has been minimized.

Copy link
Member

commented Dec 7, 2018

I like this change. It's well done.

@gasche

gasche approved these changes Dec 7, 2018

Copy link
Member

left a comment

Approved on behalf of @yallop.

@gasche

This comment has been minimized.

Copy link
Member

commented Dec 8, 2018

@Octachron would you add a Changes entry?

@Octachron Octachron force-pushed the Octachron:exception_match_doc branch from 06553eb to 8c5d81f Dec 8, 2018

@Octachron

This comment has been minimized.

Copy link
Contributor Author

commented Dec 8, 2018

Why not? (I am planning to merge on Monday).

@Octachron Octachron merged commit d3a4cba into ocaml:trunk Dec 10, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.