From cb11bcf50a4f8a6baed8f1d5f95a362077943a59 Mon Sep 17 00:00:00 2001 From: Florian Angeletti Date: Fri, 20 Sep 2019 10:19:18 +0200 Subject: [PATCH] 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 --- Changes | 6 +++++ manual/manual/refman/exten.etex | 28 --------------------- manual/manual/refman/patterns.etex | 20 ++++++++++++++- manual/manual/tutorials/moduleexamples.etex | 6 +++++ 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Changes b/Changes index c54a4a4de..76f0cf6de 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/manual/manual/refman/exten.etex b/manual/manual/refman/exten.etex index 050b37051..1f47c558c 100644 --- a/manual/manual/refman/exten.etex +++ b/manual/manual/refman/exten.etex @@ -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} diff --git a/manual/manual/refman/patterns.etex b/manual/manual/refman/patterns.etex index 36b8679cb..be6cd4a64 100644 --- a/manual/manual/refman/patterns.etex +++ b/manual/manual/refman/patterns.etex @@ -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 '|])'@. diff --git a/manual/manual/tutorials/moduleexamples.etex b/manual/manual/tutorials/moduleexamples.etex index bb68975cc..da022aa66 100644 --- a/manual/manual/tutorials/moduleexamples.etex +++ b/manual/manual/tutorials/moduleexamples.etex @@ -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