manual: move pattern open out of the extension chapter (#8950)

* move the grammar description to the pattern section of the language reference
* add a small example in the module chapter of the tutorial
master
Florian Angeletti 2019-09-20 10:19:18 +02:00 committed by GitHub
parent 452c3df125
commit cb11bcf50a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 29 deletions

View File

@ -156,6 +156,12 @@ Working version
- #1939, #2023: Implement Unix.truncate and Unix.ftruncate on Windows.
(Florent Monnier and Nicolás Ojeda Bär, review by David Allsopp)
### Manual and documentation:
- #8950: manual, move local opens in pattern out of the extension chapter
(Florian Angeletti, review and suggestion by Gabriel Scherer)
### Compiler user-interface and warnings:
- #8833: Hint for (type) redefinitions in toplevel session

View File

@ -330,34 +330,6 @@ constructors of [t] could be present.
Similarly to abstract types, the variance of type parameters
is not inferred, and must be given explicitly.
\section{Local opens for patterns}
\ikwd{let\@\texttt{let}}
\ikwd{open\@\texttt{open}} \label{s:local-opens}
(Introduced in OCaml 4.04)
\begin{syntax}
pattern:
...
| module-path '.(' pattern ')'
| module-path '.[' pattern ']'
| module-path '.[|' pattern '|]'
| module-path '.{' pattern '}'
\end{syntax}
For patterns, local opens are limited to the
@module-path'.('pattern')'@ construction. This
construction locally open the module referred to by the module path
@module-path@ in the scope of the pattern @pattern@.
When the body of a local open pattern is delimited by
@'[' ']'@, @'[|' '|]'@, or @'{' '}'@, the parentheses can be omitted.
For example, @module-path'.['pattern']'@ is equivalent to
@module-path'.(['pattern'])'@, and @module-path'.[|' pattern '|]'@ is
equivalent to @module-path'.([|' pattern '|])'@.
\section{Locally abstract types}
\ikwd{type\@\texttt{type}}
\ikwd{fun\@\texttt{fun}} \label{s:locally-abstract}

View File

@ -22,9 +22,12 @@ pattern:
| char-literal '..' char-literal
| 'lazy' pattern
| 'exception' pattern
| module-path '.(' pattern ')'
| module-path '.[' pattern ']'
| module-path '.[|' pattern '|]'
| module-path '.{' pattern '}'
\end{syntax}
See also the following language extensions:
\hyperref[s:local-opens]{local opens},
\hyperref[s-first-class-modules]{first-class modules},
\hyperref[s:attributes]{attributes} and
\hyperref[s:extension-nodes]{extension nodes}.
@ -225,3 +228,18 @@ call.
A pattern match must contain at least one value case. It is an error if
all cases are exceptions, because there would be no code to handle
the return of a value.
\subsubsection*{Local opens for patterns}
\ikwd{open\@\texttt{open}} \label{s:local-opens-pattern}
(Introduced in OCaml 4.04)
For patterns, local opens are limited to the
@module-path'.('pattern')'@ construction. This
construction locally opens the module referred to by the module path
@module-path@ in the scope of the pattern @pattern@.
When the body of a local open pattern is delimited by
@'[' ']'@, @'[|' '|]'@, or @'{' '}'@, the parentheses can be omitted.
For example, @module-path'.['pattern']'@ is equivalent to
@module-path'.(['pattern'])'@, and @module-path'.[|' pattern '|]'@ is
equivalent to @module-path'.([|' pattern '|])'@.

View File

@ -99,6 +99,12 @@ becomes
\begin{caml_example}{toplevel}
PrioQueue.[insert empty 1 "hello"];;
\end{caml_example}
This second form also works for patterns:
\begin{caml_example}{toplevel}
let at_most_one_element x = match x with
| PrioQueue.( Empty| Node (_,_, Empty,Empty) ) -> true
| _ -> false ;;
\end{caml_example}
It is also possible to copy the components of a module inside
another module by using an "include" statement. This can be