about summary refs log tree commit diff
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2014-10-16T02·32-0400
committerShea Levy <shea@shealevy.com>2014-11-15T21·25-0500
commit3d604ac88c81dd9b22252c7437a717b077897b13 (patch)
treea281888d85b6c4a848cb39a8419a8d56ef2e7329
parent997defa16617caf5fd869924558389639d1c8caf (diff)
Document functors
-rw-r--r--doc/manual/expressions/language-constructs.xml18
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/manual/expressions/language-constructs.xml b/doc/manual/expressions/language-constructs.xml
index ddb3498946b7..74809bb412d3 100644
--- a/doc/manual/expressions/language-constructs.xml
+++ b/doc/manual/expressions/language-constructs.xml
@@ -196,6 +196,24 @@ in concat { x = "foo"; y = "bar"; }</programlisting>
 
 </para>
 
+<para>A set that has a <literal>__functor</literal> attribute whose value
+is callable (i.e. is itself a function or a set with a
+<literal>__functor</literal> attribute whose value is callable) can be
+applied as if it were a function, with the set itself passed in first
+, e.g.,
+
+<programlisting>
+let add = { __functor = self: x: x + self.x; };
+    inc = add // { x = 1; };
+in inc 1
+</programlisting>
+
+evaluates to <literal>2</literal>. This can be used to attach metadata to a
+function without the caller needing to treat it specially, or to implement
+a form of object-oriented programming, for example.
+
+</para>
+
 </simplesect>