Session type explained
In type theory, session types are used to ensure correctness in concurrent programs. They guarantee that messages sent and received between concurrent programs are in the expected order and of the expected type.[1] [2] Session type systems have been adapted for both channel and actor systems.[3]
Session types are used to ensure desirable properties in concurrent and distributed systems, i.e. absence of communication errors or deadlocks, and protocol conformance.[4]
Binary versus multiparty session types
Interaction between two processes can be checked using binary session types, while interactions between more than two processes can be checked using multiparty session types.[5] In multiparty session types interactions between all participants are described using a global type, which is then projected into local types that describe communication from the local view of each participant. Importantly, the global type encodes the sequencing information of the communication, which would be lost if we were to use binary session types to encode the same communication.[6]
Formal definition of binary session types
Binary session types can be described using send operations (
), receive operations (
), branches (
), selections (
), recursion (
) and termination (
).
For example,
represents a session type
which first sends a
boolean (
), then receives an
integer (
) before finally terminating (
).
Implementations
Session types have been adapted for several existing programming languages, including:
Notes and References
- Hüttel . Hans . Lanese . Ivan . Vasconcelos . Vasco T. . Caires . Luís . Carbone . Marco . Deniélou . Pierre-Malo . Mostrous . Dimitris . Padovani . Luca . Ravara . António . Tuosto . Emilio . Vieira . Hugo Torres . Zavattaro . Gianluigi . Foundations of Session Types and Behavioural Contracts . ACM Computing Surveys . 5 April 2016 . 49 . 1 . 3:1–3:36 . 10.1145/2873052 . 3580137 . 0360-0300. 2381/38761 . free .
- Book: Ancona, Davide. Behavioral types in programming languages. 2016. Now Publishers. 978-1-68083-135-1. Hanover, Massachusetts. 1053840486.
- Fowler . Simon . Lindley . Sam . Wadler . Philip . Mixing Metaphors: Actors as Channels and Channels as Actors (Extended Version) . 10 May 2017 . cs.PL . 1611.06276.
- Scalas . Alceste . Yoshida . Nobuko . Multiparty session types, beyond duality . Journal of Logical and Algebraic Methods in Programming . June 2018 . 97 . 55–84 . 10.1016/j.jlamp.2018.01.001. 48360420 . free . 10044/1/56777 . free .
- Book: Honda . Kohei . Yoshida . Nobuko . Carbone . Marco . Proceedings of the 35th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages . Multiparty asynchronous session types . 2008 . 273–284 . 10.1145/1328438.1328472. 10044/1/26368 . 9781595936899 . 53038488 .
- A Very Gentle Introduction to Multiparty Session Types . Yoshida . Nobuko . Gheri . Lorenzo . 2019 . ICDCIT 2020 . 10.1007/978-3-030-36987-3_5.
- Web site: Session programming in Scala . alcestes.github.io . 2 November 2021 . en-us.
- Web site: STMonitor . chrisbartoloburlo.github.io . 2 November 2021 . en.
- Harvey . Paul . Fowler . Simon . Dardha . Ornela . Gay . Simon J. . Multiparty Session Types for Safe Runtime Adaptation in an Actor Language . 35th European Conference on Object-Oriented Programming (ECOOP 2021) . 2021 . 194 . 10:1–10:30 . 10.4230/LIPIcs.ECOOP.2021.10. free . 234681015 .
- Book: Jespersen . Thomas Bracht Laumann . Munksgaard . Philip . Larsen . Ken Friis . Proceedings of the 11th ACM SIGPLAN Workshop on Generic Programming . Session types for Rust . WGP 2015 . 30 August 2015 . 13–22 . 10.1145/2808098.2808100 . https://doi.org/10.1145/2808098.2808100 . Association for Computing Machinery. 9781450338103 . 18320631.
- Kokke . Wen . Rusty Variation: Deadlock-free Sessions with Failure in Rust . Electronic Proceedings in Theoretical Computer Science . 12 September 2019 . 304 . 48–60 . 10.4204/EPTCS.304.4 . 1909.05970 . 198166990 . 2075-2180.
- Yoshida . Nobuko . Neykova . Rumyana . Multiparty Session Actors . Logical Methods in Computer Science . 29 March 2017 . 13 . 1 . 10.23638/LMCS-13(1:17)2017 . 65240382 . en.
- Fowler . Simon . An Erlang Implementation of Multiparty Session Actors . Electronic Proceedings in Theoretical Computer Science . 10 August 2016 . 223 . 36–50 . 10.4204/EPTCS.223.3 . 1608.03321 . 418549 . 2075-2180.
- Padovani . Luca . A simple library implementation of binary sessions . Journal of Functional Programming . 2017 . 27 . e4 . 10.1017/S0956796816000289 . 2318/1634956 . 19776781 . en . 0956-7968. free .
- Imai . Keigo . Yoshida . Nobuko . Yuen . Shoji . Session-ocaml: A session-based library with polarities and lenses . Science of Computer Programming . March 2019 . 172 . 135–159 . 10.1016/j.scico.2018.08.005 . 69673075 . en . 0167-6423. free . 10044/1/63748 . free .
- Web site: Session OCaml . Imai . Keigo. www.ct.info.gifu-u.ac.jp . 2 November 2021.
- Kokke . Wen . Dardha . Ornela . Deadlock-Free Session Types in Linear Haskell . 26 March 2021 . cs.PL . 2103.14481.
- Web site: Java Typestate Checker . .
- Bacchiani . Lorenzo . Bravetti . Mario . Giunti . Marco . Mota . João . Ravara . António . A Java typestate checker supporting inheritance . Sci. Comput. Program. . 2022 . 221 . 102844 . 10.1016/j.scico.2022.102844 . 250940803 . free . 10362/145315 . free .
- Book: Mota . João . Giunti . Marco . Ravara . António . Java Typestate Checker . Proceedings of COORDINATION 2021 . Lecture Notes in Computer Science . 2021 . 12717 . 121–133 . 10.1007/978-3-030-78142-2_8 . 978-3-030-78141-5 . 235383301 . https://doi.org/10.1007/978-3-030-78142-2_8.
- Web site: Rubicini . Alessio . Padovani . Luca . 2023 . Swift Sessions: a library implementation of binary session types in Swift . .