一句话:通过双向翻译刻画函数式与命令式会话类型演算的表达力差异。
命令式会话类型为会话通信提供命令式接口:通道引用是一等对象,操作会改变其类型状态。相较使用线性类型管理通道的函数式接口,命令式程序表面更简单,却需显式跟踪通信状态。本文重新审视早期命令式会话类型工作,给出从命令式演算到线性函数式会话类型系统的保类型、保语义翻译,说明函数式方法蕴含命令式方法;同时给出反向的无类型翻译并证明其保语义。进一步限制函数式演算的类型系统,使反向翻译也保类型,从而精确刻画两个演算在表达力上的差异,并表明命令式演算表达力不足主要源于其类型系统限制。
Imperative session types provide an imperative interface to session-typed communication. In such an interface, channel references are first-class objects with operations that change the typestate of the channel. Compared to functional session type APIs, the program structure is simpler at the surface, but typestate is required to model the current state of communication throughout. Following an early work that explored the imperative approach, a significant body of work on session types has neglected the imperative approach and opts for a functional approach that uses linear types to manage channel references soundly. We demonstrate that the functional approach subsumes the early work on imperative session types by exhibiting a typing and semantics preserving translation into a system of linear functional session types. We further show that the untyped backwards translation from the functional to the imperative calculus is semantics preserving. We restrict the type system of the functional calculus such that the backwards translation becomes type preserving. Thus, we precisely capture the difference in expressiveness of the two calculi and conclude that the lack of expressiveness in the imperative calculus is largely due to restrictions imposed by its type system.