In the last decades a great deal of effort in the type systems
community has been devoted to investigate the so called session types. For instance, if a client process is connected by means of a channel k to a server process that performs sums, the type of the channel k will be ![int].![int].?(int).endmeaning that k is a channel through which an integer is sent, then another integer is sent and then an integer (the result produced by the server) is expected. Of course this is the description of the client-server interaction seen from the point of view of the client. The type of the very same channel, looked at from the server point of view is instead ?(int) ?(int) ![int].end
In order to have the possibility of describing complex protocols, the
syntax of session types is enriched with branching and selection. Here is the syntax of session types: S::= end | ?(G).S | ![G].S | &{ l1 : S1,...,ln : Sn } | ⊕{ l1 : S1,..., ln : Sn }Whereas a type &{...} denotes a choice that is influenced by a message we receive from the other end of the channel, the type ⊕{...} denotes a choice that depends entirely on ourselves. G denotes a ground type, like Int, Bool ... Example: (by Dezani, de'Liguoro) To illustrate these concepts and their formal representation, let us consider the following protocol, which describes a simplified interaction between a customer (Client) and an ATM, Automated Teller Machine (Server):
?(String). ⊕{success : &{deposit : ?(Real). ![Real]. end, withdraw : ? Real. ⊕{dispense : end, overdraft : end } } failure : end }The client's point of view can be obtained by simply replacing '!' by '?' and vice versa, and by replacing '&' by '⊕' and vice versa: ![String]. &{success : ⊕{deposit : ![Real]. ?(Real). end, withdraw : ! Real. &{dispense : end, overdraft : end } } failure : end }
Notice that, differently from PICT (and π-calculus), a session channel can be used only by two processes, so it can never happen, if k is a session channel, something like k!v.Q | k!w.R | k?y=P (*)(we consider here, for simplicity, a syncronous version of π-calculus and PICT)
The definition of a port in S-PICT could be port a : session Swhere S is a session type describing the protocol used in the session from the point of view of the server. The the request of opening a session, in S-PICT, could be request a (k).PBy running such process we request a session on the port a to be opened with anyone willing to do so. The (bound) name k is used to refer to the channel name through which the session will be carried on in P. The request action is blocking. To accept a session-opening request a process of S-PICT could use accept a (k).P
request a (k).P | accept a (k).Qthis subprocess reduces (evolves) to new k : S P | Q
The operational semantics of label exchanging, instead, is the following: k << lh:P | k >> {l1:P1,..,ln:Pn}this reduces to P | Ph
Example (continued):
port a : session Sthe process describing a possible client of the ATM could be request a (k). k!identifier. k >> {success : if · · · then k << deposit: k ! amount. k ? x =0 else k << withdraw: k ! amount. k >> {dispense: · · overdraft: · · } failure : 0 }whereas the process ATM could be def accept a (h). h ? x = if · · · then h << success : h >> {deposit : h ? y = · · · h ! balance. 0 withdraw : h ? z = if · · · then h << dispense: · · else h << overdraft: · · } else h << failure : 0where def means we are considering a replication version of the ATM process, since it can serve many clients, each with a private session channel.
Now, if the ATM process and the client process are well typed in S-PICT, we are guaranteed
that the exchanges through the session channel will always follow the protocol
described by the session type associated with the port a. In general, a type system for processes with session types guarantees that
Particular versions of session types can be used to describe also multiparty interactions. There exist many experimental extensions with session types of actual programmaing languages. For instance Haskell, Scala, Java (SessionJ) and others. Extensions with session types are currently investigated also for Erlang. In our course we shall introduce Scribble, a language (based on session types) for the description of application-level protocols among communicating systems. |