aboutsummaryrefslogtreecommitdiffstats
path: root/system/doc/design_principles/spec_proc.xml
diff options
context:
space:
mode:
Diffstat (limited to 'system/doc/design_principles/spec_proc.xml')
-rw-r--r--system/doc/design_principles/spec_proc.xml31
1 files changed, 29 insertions, 2 deletions
diff --git a/system/doc/design_principles/spec_proc.xml b/system/doc/design_principles/spec_proc.xml
index a02315ac68..5b156ac263 100644
--- a/system/doc/design_principles/spec_proc.xml
+++ b/system/doc/design_principles/spec_proc.xml
@@ -522,9 +522,36 @@ init(Parent, Name, Module) ->
-module(db).
-behaviour(simple_server).
--export([init/0, handle_req/2, terminate/0]).
+-export([init/1, handle_req/2, terminate/0]).
...</code>
+
+ <p>The contracts specified with <c>-callback</c> attributes in
+ behaviour modules can be further refined by adding <c>-spec</c>
+ attributes in callback modules. This can be useful as
+ <c>-callback</c> contracts are usually generic. The same callback
+ module with contracts for the callbacks:</p>
+
+ <code type="none">
+-module(db).
+-behaviour(simple_server).
+
+-export([init/1, handle_req/2, terminate/0]).
+
+-record(state, {field1 :: [atom()], field2 :: integer()}).
+
+-type state() :: #state{}.
+-type request() :: {'store', term(), term()};
+ {'lookup', term()}.
+
+...
+
+-spec handle_req(request(), state()) -> {'ok', term()}.
+
+...</code>
+
+ <p>Each <c>-spec</c> contract is to be a subtype of the respective
+ <c>-callback</c> contract.</p>
+
</section>
</chapter>
-