Session type

From HandWiki

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 ([math]\displaystyle{ ! }[/math]), receive operations ([math]\displaystyle{ ? }[/math]), branches ([math]\displaystyle{ \& }[/math]), selections ([math]\displaystyle{ \oplus }[/math]), recursion ([math]\displaystyle{ rec }[/math]) and termination ([math]\displaystyle{ end }[/math]).[2]

For example, [math]\displaystyle{ S = \; !bool.?int.end }[/math] represents a session type [math]\displaystyle{ S }[/math] which first sends a boolean ([math]\displaystyle{ !bool }[/math]), then receives an integer ([math]\displaystyle{ ?int }[/math]) before finally terminating ([math]\displaystyle{ end }[/math]).

Implementations

Session types have been adapted for several existing programming languages, including:

References

  1. Hüttel, Hans; Lanese, Ivan; Vasconcelos, Vasco T.; Caires, Luís; Carbone, Marco; Deniélou, Pierre-Malo; Mostrous, Dimitris; Padovani, Luca et al. (5 April 2016). "Foundations of Session Types and Behavioural Contracts". ACM Computing Surveys 49 (1): 3:1–3:36. doi:10.1145/2873052. ISSN 0360-0300. https://doi.org/10.1145/2873052. 
  2. 2.0 2.1 Ancona, Davide (2016). Behavioral types in programming languages. Hanover, Massachusetts: Now Publishers. ISBN 978-1-68083-135-1. OCLC 1053840486. https://www.worldcat.org/oclc/1053840486. 
  3. Fowler, Simon; Lindley, Sam; Wadler, Philip (10 May 2017). "Mixing Metaphors: Actors as Channels and Channels as Actors (Extended Version)". arXiv:1611.06276 [cs.PL].
  4. Scalas, Alceste; Yoshida, Nobuko (June 2018). "Multiparty session types, beyond duality". Journal of Logical and Algebraic Methods in Programming 97: 55–84. doi:10.1016/j.jlamp.2018.01.001. 
  5. Honda, Kohei; Yoshida, Nobuko; Carbone, Marco (2008). "Multiparty asynchronous session types". Proceedings of the 35th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages. pp. 273–284. doi:10.1145/1328438.1328472. ISBN 9781595936899. 
  6. Yoshida, Nobuko; Gheri, Lorenzo (2019). "A Very Gentle Introduction to Multiparty Session Types". ICDCIT 2020. doi:10.1007/978-3-030-36987-3_5. 
  7. 7.0 7.1 "Session programming in Scala" (in en-us). https://alcestes.github.io/lchannels/. 
  8. "STMonitor" (in en). https://chrisbartoloburlo.github.io/stmonitor/. 
  9. Harvey, Paul; Fowler, Simon; Dardha, Ornela; Gay, Simon J. (2021). "Multiparty Session Types for Safe Runtime Adaptation in an Actor Language". 35th European Conference on Object-Oriented Programming (ECOOP 2021) 194: 10:1–10:30. doi:10.4230/LIPIcs.ECOOP.2021.10. 
  10. Jespersen, Thomas Bracht Laumann; Munksgaard, Philip; Larsen, Ken Friis (30 August 2015). "Session types for Rust". Proceedings of the 11th ACM SIGPLAN Workshop on Generic Programming. WGP 2015. Association for Computing Machinery. pp. 13–22. doi:10.1145/2808098.2808100. ISBN 9781450338103. https://doi.org/10.1145/2808098.2808100. 
  11. Kokke, Wen (12 September 2019). "Rusty Variation: Deadlock-free Sessions with Failure in Rust". Electronic Proceedings in Theoretical Computer Science 304: 48–60. doi:10.4204/EPTCS.304.4. ISSN 2075-2180. https://doi.org/10.4204/EPTCS.304.4. 
  12. Yoshida, Nobuko; Neykova, Rumyana (29 March 2017). "Multiparty Session Actors" (in en). Logical Methods in Computer Science 13 (1). doi:10.23638/LMCS-13(1:17)2017. https://doi.org/10.23638/LMCS-13(1:17)2017. 
  13. Fowler, Simon (10 August 2016). "An Erlang Implementation of Multiparty Session Actors". Electronic Proceedings in Theoretical Computer Science 223: 36–50. doi:10.4204/EPTCS.223.3. ISSN 2075-2180. https://doi.org/10.4204/EPTCS.223.3. 
  14. Padovani, Luca (2017). "A simple library implementation of binary sessions" (in en). Journal of Functional Programming 27: e4. doi:10.1017/S0956796816000289. ISSN 0956-7968. https://doi.org/10.1017/S0956796816000289. 
  15. Imai, Keigo; Yoshida, Nobuko; Yuen, Shoji (March 2019). "Session-ocaml: A session-based library with polarities and lenses" (in en). Science of Computer Programming 172: 135–159. doi:10.1016/j.scico.2018.08.005. ISSN 0167-6423. 
  16. Imai, Keigo. "Session OCaml". https://www.ct.info.gifu-u.ac.jp/~keigoi/session-ocaml/. 
  17. Kokke, Wen; Dardha, Ornela (26 March 2021). "Deadlock-Free Session Types in Linear Haskell". arXiv:2103.14481 [cs.PL].
  18. "Java Typestate Checker". https://github.com/jdmota/java-typestate-checker. 
  19. Bacchiani, Lorenzo; Bravetti, Mario; Giunti, Marco; Mota, João; Ravara, António (2022). "A Java typestate checker supporting inheritance". Sci. Comput. Program. 221: 102844. doi:10.1016/j.scico.2022.102844. 
  20. Mota, João; Giunti, Marco; Ravara, António (2021). Java Typestate Checker. Lecture Notes in Computer Science. 12717. 121–133. doi:10.1007/978-3-030-78142-2_8. ISBN 978-3-030-78141-5. https://doi.org/10.1007/978-3-030-78142-2_8.