@@ -41,21 +41,22 @@ import Network.TypedProtocol.Core as Core
4141-- * the protocol itself;
4242-- * the client\/server role;
4343-- *.the current protocol state;
44+ -- * the local state type;
4445-- * the monad in which the peer operates; and
4546-- * the type of any final result once the peer terminates.
4647--
4748-- For example:
4849--
49- -- > pingPongClientExample :: Peer PingPong AsClient StIdle m ()
50- -- > pingPongServerExample :: Peer PingPong AsServer StIdle m Int
50+ -- > reqRespClientExample :: Peer (ReqResp FileAPI) AsClient StIdle State m ()
51+ -- > reqRespServerExample :: Peer (ReqResp FileAPI) AsServer StIdle State m Int
5152--
5253-- The actions that a peer can take are:
5354--
54- -- * to perform local monadic effects
55- -- * to terminate with a result (but only in a terminal protocol state)
56- -- * to send a message (but only in a protocol state in which we have agency)
57- -- * to wait to receive a message (but only in a protocol state in which the
58- -- other peer has agency)
55+ -- * perform a local monadic effect,
56+ -- * terminate with a result (but only in a terminal protocol state),
57+ -- * send a message (but only in a protocol state in which we have agency),
58+ -- * wait to receive a message (but only in a protocol state in which the
59+ -- other peer has agency).
5960--
6061-- The 'Yield', 'Await' and 'Done' constructors require to provide an evidence
6162-- that the appropriate peer has agency. This information is supplied using
@@ -96,13 +97,19 @@ data Peer ps pr st f m a where
9697 -- ^ monadic continuation
9798 -> Peer ps pr st f m a
9899
99- -- | Send a message to the other peer and then continue. This takes the
100- -- message and the continuation. It also requires evidence that we have
101- -- agency for this protocol state and thus are allowed to send messages.
100+ -- | Send a message to the other peer and then continue. The constructor
101+ -- requires evidence that we have agency for this protocol state and thus are
102+ -- allowed to send messages. It takes local state associated to the source
103+ -- and target protocol state of the message that is sent. This state is only
104+ -- maintained locally, never shared remotely. It also takes the message and
105+ -- the continuation. It also requires evidence that we have agency for this
106+ -- protocol state and thus are allowed to send messages.
102107 --
103108 -- Example:
104109 --
105- -- > Yield ReflClientAgency MsgPing $ ...
110+ -- > Yield ReflClientAgency (StateBusy (ReadFile /etc/os-release))
111+ -- > StateIdle
112+ -- > $ MsgResp "..."
106113 --
107114 Yield
108115 :: forall ps pr (st :: ps ) (st' :: ps ) f m a .
@@ -113,9 +120,9 @@ data Peer ps pr st f m a where
113120 => WeHaveAgencyProof pr st
114121 -- ^ agency singleton
115122 -> f st
116- -- ^ initial protocol state
123+ -- ^ associated local state to the source protocol state 'st'
117124 -> f st'
118- -- ^ final protocol state
125+ -- ^ associated local state to the target protocol state `st'`
119126 -> Message ps st st'
120127 -- ^ protocol message
121128 -> Peer ps pr st' f m a
@@ -134,10 +141,13 @@ data Peer ps pr st f m a where
134141 --
135142 -- Example:
136143 --
137- -- > Await ReflClientAgency $ \msg ->
138- -- > case msg of
139- -- > MsgDone -> ...
140- -- > MsgPing -> ...
144+ -- > Await ReflClientAgency $ \f msg ->
145+ -- > case (f, msg) of
146+ -- > (StateBusy (ReadFile path), MsgResp resp) ->
147+ -- > ( _continuation
148+ -- > , StateIdle
149+ -- > )
150+ --
141151 --
142152 Await
143153 :: forall ps pr (st :: ps ) f m a .
@@ -148,10 +158,21 @@ data Peer ps pr st f m a where
148158 -- ^ agency singleton
149159 -> (forall (st' :: ps ).
150160 f st
161+ -- associated local state to the source protocol state 'st'
162+ --
163+ -- TODO: input-output-hk/typed-protocols#57
151164 -> Message ps st st'
152165 -> ( Peer ps pr st' f m a
153166 , f st'
154167 )
168+ -- continuation and associated local state to the target protocol
169+ -- state `st'`
170+ --
171+ -- NOTE: the API is limited to pure transition of local state e.g.
172+ -- `f st -> Message ps st st' -> f st'`,
173+ -- see https://github.com/input-output-hk/typed-protocols/discussions/63
174+ --
175+ -- TODO: input-output-hk/typed-protocols#57
155176 )
156177 -- ^ continuation
157178 -> Peer ps pr st f m a
0 commit comments