From 3d604ac88c81dd9b22252c7437a717b077897b13 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Wed, 15 Oct 2014 22:32:08 -0400 Subject: [PATCH] Document functors --- doc/manual/expressions/language-constructs.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/doc/manual/expressions/language-constructs.xml b/doc/manual/expressions/language-constructs.xml index ddb349894..74809bb41 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"; } +A set that has a __functor attribute whose value +is callable (i.e. is itself a function or a set with a +__functor attribute whose value is callable) can be +applied as if it were a function, with the set itself passed in first +, e.g., + + +let add = { __functor = self: x: x + self.x; }; + inc = add // { x = 1; }; +in inc 1 + + +evaluates to 2. 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. + + +