This document discusses using session types to specify and check the behavior of stateful RESTful systems. It presents an example of modeling a parcel delivery workflow as a session type in Scala. Session types define the possible state transitions and messages that can be exchanged, enabling contract checking. The example shows how session types catch errors like invalid initial states, forbidden transitions, or messages being sent out of order. Session types provide a way to encode state machines and communication protocols to make them verifiable by programming tools.
41. Communication steps
case class Stop(msg: String)
case class In [R[S<:State],A<:State,B<:State,+C](recv: R[A] => (C,R[B]))
(implicit stateTransition: ~>[A,B])
case class Out[+R[S<:State],A<:State,+C](data: R[A], cont: C)
50. Close the post
sealed abstract class ~>[-A,+B]
//implicit case object GoToThePost extends ~>[Packaged,Sending]
implicit case object AcceptFromSender extends ~>[Sending,Moving]
implicit case object BringToTheAddress extends ~>[Moving,Received]
implicit case object GiveToReceiver extends ~>[Received,Delivered]
implicit case object GetAngry extends ~>[Moving,Destroyed]
implicit case object DrinkAlcohol extends ~>[Moving,Lost]
implicit case object StopDrinking extends ~>[Lost,Moving]
64. Contract first, session types never?
• No API Specification standard is about REST
• REST “allows” for client-side contract checking
• Session Types don’t fit RESTful communications