summaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
authorDrup <drupyog@zoho.com>2016-02-02 18:26:11 +0100
committerDrup <drupyog@zoho.com>2016-02-05 14:47:09 +0100
commita917a29c9cc3988e62a8b9e9871a7e00a7ef59f1 (patch)
tree8a3b5e5d6e6e5e57346f7c5ba2c59b291d6c3479 /manual
parent5775d993884556947aeb3432df15e36b4c3ccecc (diff)
downloadocaml-a917a29c9cc3988e62a8b9e9871a7e00a7ef59f1.tar.gz
Manual for attributes.
Diffstat (limited to 'manual')
-rw-r--r--manual/manual/refman/exten.etex26
1 files changed, 17 insertions, 9 deletions
diff --git a/manual/manual/refman/exten.etex b/manual/manual/refman/exten.etex
index 23b7945cb3..d3528e041b 100644
--- a/manual/manual/refman/exten.etex
+++ b/manual/manual/refman/exten.etex
@@ -1416,7 +1416,8 @@ The last two entries are valid for any $n > 3$.
\section{Attributes}\label{s:attributes}
-(Introduced in OCaml 4.02)
+(Introduced in OCaml 4.02,
+infix notations for constructs other than expressions added in 4.03)
Attributes are ``decorations'' of the syntax tree which are mostly
ignored by the type-checker but can be used by external tools. An
@@ -1584,18 +1585,25 @@ cannot be attached to these floating attributes in @class-field-spec@
and @class-field@.)
-It is also possible to specify attributes on expressions using an
-infix syntax. This applies to all expressions starting with one or
-two keywords: "assert", "begin", "for", "fun", "function", "if",
-"lazy", "let", "let module", "let open", "match", "new", "object",
-"try", "while". Those expressions supports adding one or several
-attributes just after those initial keyword(s). For instance:
+It is also possible to specify attributes using an infix syntax. For instance:
+
+\begin{verbatim}
+let[@foo] x = 2 in x + 1 === (let x = 2 [@@foo] in x + 1)
+begin[@foo][@bar x] ... end === (begin ... end)[@foo][@@bar x]
+module[@foo] M = ... === module M = ... [@@foo]
+type[@foo] t = T === type t = T [@@foo]
+method[@foo] m = ... === method m = ... [@@foo]
+\end{verbatim}
+
+For "let", the attributes are applied to each bindings:
\begin{verbatim}
-let [@foo][@bar x] x = 2 in x + 1 === (let x = 2 in x + 1)[@foo][@bar x]
-begin[@foo] ... end === (begin ... end)[@foo]
+let[@foo] x = 2 and y = 3 in x + y === (let x = 2 [@@foo] and y = 3 in x + y)
+let[@foo] x = 2
+and[@bar] y = 3 in x + y === (let x = 2 [@@foo] and y = 3 [@bar] in x + y)
\end{verbatim}
+
\subsection{Built-in attributes}
Some attributes are understood by the type-checker: