Skip to main content

Session Types Without Sophistry

System Description

  • Conference paper
  • First Online:

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 12073))

Abstract

Whereas ordinary types approximate the results, session types approximate communication among computations. As a form of typestate, they describe not only what is communicated now but also what is to be communicated next. Writing session-typed programs in an ordinary programming language such an OCaml requires inordinary cleverness to simulate type-level computations and linear typing – meaning the implementation and the error messages are very hard to understand. One is constantly reminded of template metaprogramming in C++.

We present a system exploring a very different approach to session typing: lowering type-level sophistry to ordinary programming, while maintaining the static assurances. Error messages are detailed and customizable, and one can use an ordinary debugger to investigate session-type problems. Our system is a binary-session–typed DSL for service-oriented programming in OCaml, supporting multiple communication channels, internal and external choices, recursion, and also channel delegation.

The key idea is staging: ordinary run-time checks in the generator play the role of “type-checks” from the point of view of the generated program. What is a fancy type to the latter is ordinary data to the generator.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Notes

  1. 1.

    Binary session type systems like [14] and its successors, used in many libraries including ours, do not in general prevent deadlocks (see Sect. 5).

  2. 2.

    What we call an endpoint, Yoshida and Vasconcelos [51, §3] call a “polarized channel”, following Gay and Hole [12].

  3. 3.

    The right-associative infix operator @@ of low precedence is application: f @@ x + 1 is the same as f (x + 1) but avoids the parentheses. The operator is the analogue of in Haskell.

  4. 4.

    It should also be possible to supply a session type and check an expression against it, to verify its communication obeys the protocol stated in the type. After all, if we can infer a session type, we can check against it. However, we have not yet offered this facility in the public library interface.

  5. 5.

    To improve readability, we adjusted indentation and removed module references, while the rest is left as-is. Variables and are generated via let-insertion.

  6. 6.

    The code does not say that rendez-vous with itself, which is impossible. Communications on a are synchronous (i.e. and blocks until its counterpart becomes available) while those on session endpoints are asynchronous.

  7. 7.

    Ours and are called and in [51] (we changed the names to avoid association with exceptions).

  8. 8.

    The language is quite like the STATE language in [27, §7]: the imperative part of Reynolds’ Idealized Algol, as pointed out by Bob Atkey. Instead of we write .

  9. 9.

    That tutorial paper also compares canonical structures to related approaches, in particular, implicits and type classes.

References

  1. Bernardi, G., Dardha, O., Gay, S.J., Kouzapas, D.: On duality relations for session types. In: Maffei, M., Tuosto, E. (eds.) TGC 2014. LNCS, vol. 8902, pp. 51–66. Springer, Heidelberg (2014). https://doi.org/10.1007/978-3-662-45917-1_4

    Chapter  Google Scholar 

  2. Bernardi, G., Hennessy, M.: Using higher-order contracts to model session types. Logical Methods Comput. Sci. 12(2) (2016). https://doi.org/10.2168/LMCS-12(2:10)2016

  3. Bono, V., Messa, C., Padovani, L.: Typing copyless message passing. In: Barthe, G. (ed.) ESOP 2011. LNCS, vol. 6602, pp. 57–76. Springer, Heidelberg (2011). https://doi.org/10.1007/978-3-642-19718-5_4

    Chapter  Google Scholar 

  4. Castro, D., Hu, R., Jongmans, S.S., Ng, N., Yoshida, N.: Distributed programming using role parametric session types in go. In: 46th ACM SIGPLAN Symposium on Principles of Programming Languages, vol. 3, pp. 29:1–29:30. ACM (2019). https://doi.org/10.1145/3290342

  5. Cooper, E., Lindley, S., Wadler, P., Yallop, J.: Links: web programming without tiers. In: de Boer, F.S., Bonsangue, M.M., Graf, S., de Roever, W.-P. (eds.) FMCO 2006. LNCS, vol. 4709, pp. 266–296. Springer, Heidelberg (2007). https://doi.org/10.1007/978-3-540-74792-5_12

    Chapter  Google Scholar 

  6. Dardha, O., Giachino, E., Sangiorgi, D.: Session types revisited. In: PPDP 2012: Proceedings of the 14th Symposium on Principles and Practice of Declarative Programming, pp. 139–150. ACM, New York (2012)

    Google Scholar 

  7. Fluet, M., Morrisett, G., Ahmed, A.: Linear regions are all you need. In: Sestoft, P. (ed.) ESOP 2006. LNCS, vol. 3924, pp. 7–21. Springer, Heidelberg (2006). https://doi.org/10.1007/11693024_2

    Chapter  Google Scholar 

  8. Foster, J.N., Greenwald, M.B., Moore, J.T., Pierce, B.C., Schmitt, A.: Combinators for bidirectional tree transformations: a linguistic approach to the view-update problem. ACM Trans. Program. Lang. Syst. 29(3), 17 (2007). https://doi.org/10.1145/1232420.1232424

  9. Fowler, S., Lindley, S., Morris, J.G., Decova, S.: Exceptional asynchronous session types: session types without tiers. PACMPL 3(POPL), 28:1–28:29 (2019)

    Google Scholar 

  10. Furuse, J.: Typeful PPX and value implicits. In: OCaml 2015: The OCaml Users and Developers Workshop (2015). https://bitbucket.org/camlspotter/ppx_implicits

  11. Garrigue, J.: Safeio (a mailing-list post) (2006). https://github.com/garrigue/safeio

  12. Gay, S., Hole, M.: Subtyping for session types in the Pi-calculus. Acta Informatica 42(2/3), 191–225 (2005). https://doi.org/10.1007/s00236-005-0177-z

  13. Henry, G., Garrigue, J.: Runtime types in OCaml. In: OCaml 2013: The OCaml Users and Developers Workshop (2013). https://ocaml.org/meetings/ocaml/2013/proposals/runtime-types.pdf

  14. Honda, K., Vasconcelos, V.T., Kubo, M.: Language primitives and type discipline for structured communication-based programming. In: Hankin, C. (ed.) ESOP 1998. LNCS, vol. 1381, pp. 122–138. Springer, Heidelberg (1998). https://doi.org/10.1007/BFb0053567

    Chapter  Google Scholar 

  15. Honda, K., Yoshida, N., Carbone, M.: Multiparty asynchronous session types. J. ACM 63(1), 9:1–9:67 (2016). http://doi.acm.org/10.1145/2827695

  16. Hu, R., Yoshida, N.: Hybrid session verification through endpoint API generation. In: Stevens, P., Wąsowski, A. (eds.) FASE 2016. LNCS, vol. 9633, pp. 401–418. Springer, Heidelberg (2016). https://doi.org/10.1007/978-3-662-49665-7_24

    Chapter  Google Scholar 

  17. Hu, R., Yoshida, N.: Explicit connection actions in multiparty session types. In: Huisman, M., Rubin, J. (eds.) FASE 2017. LNCS, vol. 10202, pp. 116–133. Springer, Heidelberg (2017). https://doi.org/10.1007/978-3-662-54494-5_7

    Chapter  Google Scholar 

  18. Hu, R., Yoshida, N., Honda, K.: Session-based distributed programming in Java. In: Vitek, J. (ed.) ECOOP 2008. LNCS, vol. 5142, pp. 516–541. Springer, Heidelberg (2008). https://doi.org/10.1007/978-3-540-70592-5_22

    Chapter  Google Scholar 

  19. Igarashi, A., Kobayashi, N.: Resource usage analysis. ACM Trans. Program. Lang. Syst. 27(2), 264–313 (2005)

    Article  Google Scholar 

  20. Imai, K., Garrigue, J.: Lightweight linearly-typed programming with lenses and monads. J. Inf. Process. 27, 431–444 (2019). https://doi.org/10.2197/ipsjjip.27.431

  21. Imai, K., Yoshida, N., Yuen, S.: Session-ocaml: a session-based library with polarities and lenses. In: Jacquet, J.-M., Massink, M. (eds.) COORDINATION 2017. LNCS, vol. 10319, pp. 99–118. Springer, Cham (2017). https://doi.org/10.1007/978-3-319-59746-1_6

    Chapter  Google Scholar 

  22. Imai, K., Yuen, S., Agusa, K.: Session type inference in Haskell. In: Proceedings Third Workshop on Programming Language Approaches to Concurrency and communication-cEntric Software, PLACES 2010, Paphos, Cyprus, 21st March 2010, pp. 74–91 (2010). https://doi.org/10.4204/EPTCS.69.6

  23. Jespersen, T.B.L., Munksgaard, P., Larsen, K.F.: Session types for rust. In: WGP 2015: Proceedings of the 11th ACM SIGPLAN Workshop on Generic Programming, pp. 13–22. ACM (2015). https://doi.org/10.1145/2808098.2808100

  24. Kiselyov, O.: Typed tagless final interpreters. In: Gibbons, J. (ed.) Generic and Indexed Programming. LNCS, vol. 7470, pp. 130–174. Springer, Heidelberg (2012). https://doi.org/10.1007/978-3-642-32202-0_3

    Chapter  Google Scholar 

  25. Kiselyov, O.: The design and implementation of BER MetaOCaml. In: Codish, M., Sumii, E. (eds.) FLOPS 2014. LNCS, vol. 8475, pp. 86–102. Springer, Cham (2014). https://doi.org/10.1007/978-3-319-07151-0_6

    Chapter  Google Scholar 

  26. Kiselyov, O.: Reconciling Abstraction with High Performance: A MetaOCaml approach. Foundations and Trends in Programming Languages, Now Publishers (2018)

    Google Scholar 

  27. Kiselyov, O.: Effects without monads: non-determinism - back to the Meta Language. Electron. Proc. Theor. Comp. Sci. 294, 15–40 (2019). https://arxiv.org/abs/1905.06544

  28. Kiselyov, O., Peyton Jones, S., Shan, C.-c.: Fun with type functions. In: Roscoe, A.W., Jones, C.B., Wood, K.R. (eds.) Reflections on the Work of C.A.R. Hoare, pp. 301–331. Springer, London (2010). https://doi.org/10.1007/978-1-84882-912-1_14

  29. Kiselyov, O., Shan, C.-c.: Lightweight monadic regions. In: Gill, A. (ed.) Haskell ’08: Proceedings of the First ACM SIGPLAN Symposium on Haskell, pp. 1–12. ACM Press, New York, 25 September 2008

    Google Scholar 

  30. Lange, J., Yoshida, N.: Verifying asynchronous interactions via communicating session automata. In: Dillig, I., Tasiran, S. (eds.) CAV 2019. LNCS, vol. 11561, pp. 97–117. Springer, Cham (2019). https://doi.org/10.1007/978-3-030-25540-4_6

    Chapter  Google Scholar 

  31. Lindley, S., Morris, J.G.: A semantics for propositions as sessions. In: Vitek, J. (ed.) ESOP 2015. LNCS, vol. 9032, pp. 560–584. Springer, Heidelberg (2015). https://doi.org/10.1007/978-3-662-46669-8_23

    Chapter  Google Scholar 

  32. Lindley, S., Morris, J.G.: Embedding session types in Haskell. In: Haskell 2016: Proceedings of the 9th International Symposium on Haskell, pp. 133–145. ACM (2016). https://doi.org/10.1145/2976002.2976018

  33. Lindley, S., Morris, J.G.: Lightweight Functional Session Types (2017). In [45 §12]

    Google Scholar 

  34. Mahboubi, A., Tassi, E.: Canonical structures for the working Coq user. In: Blazy, S., Paulin-Mohring, C., Pichardie, D. (eds.) ITP 2013. LNCS, vol. 7998, pp. 19–34. Springer, Heidelberg (2013). https://doi.org/10.1007/978-3-642-39634-2_5

    Chapter  Google Scholar 

  35. Neubauer, M., Thiemann, P.: An implementation of session types. In: Jayaraman, B. (ed.) PADL 2004. LNCS, vol. 3057, pp. 56–70. Springer, Heidelberg (2004). https://doi.org/10.1007/978-3-540-24836-1_5

    Chapter  Google Scholar 

  36. Neykova, R., Hu, R., Yoshida, N., Abdeljallal, F.: A session type provider: compile-time API generation of distributed protocols with refinements in f#. In: Proceedings of the 27th International Conference on Compiler Construction, CC 2018, February 24–25, 2018, Vienna, Austria, pp. 128–138. ACM (2018). https://doi.org/10.1145/3178372.3179495

  37. Orchard, D., Yoshida, N.: Effects as sessions, sessions as effects. In: POPL 2016: 43th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 568–581. ACM (2016). https://doi.org/10.1145/2837614.2837634

  38. Orchard, D., Yoshida, N.: Session Types with Linearity in Haskell (2017). In [45 §10]

    Google Scholar 

  39. Padovani, L.: A simple library implementation of binary sessions. J. Func. Program. 27, e4 (2016)

    Article  MathSciNet  Google Scholar 

  40. Pickering, M., Gibbons, J., Wu, N.: Profunctor optics: modular data accessors. Art Sci. Eng. Program. 1(2), Article 7 (2017). https://doi.org/10.22152/programming-journal.org/2017/1/7

  41. Pucella, R., Tov, J.A.: Haskell session types with (almost) no class. In: Gill, A. (ed.) Proceedings of the 1st ACM SIGPLAN Symposium on Haskell, pp. 25–36. ACM Press, New York, 25 September 2008

    Google Scholar 

  42. Sackman, M., Eisenbach, S.: Session types in Haskell: updating message passing for the 21st century. Technical report, Imperial College London, June 2008. http://pubs.doc.ic.ac.uk/session-types-in-haskell/

  43. Scalas, A., Yoshida, N.: Lightweight session programming in scala. In: ECOOP 2016: 30th European Conference on Object-Oriented Programming. LIPIcs, vol. 56, pp. 21:1–21:28. Dagstuhl (2016). https://doi.org/10.4230/LIPIcs.ECOOP.2016.21

  44. Scribble: Scribble home page (2019). http://www.scribble.org

  45. Simon Gay, A.R. (ed.): Behavioural Types: from Theory to Tools. River Publisher (2017). https://www.riverpublishers.com/research_details.php?book_id=439

  46. Strom, R.E., Yellin, D.M.: Extending typestate checking using conditional liveness analysis. IEEE Trans. Softw. Eng. 19(5), 478–485 (1993)

    Article  Google Scholar 

  47. Takeuchi, K., Honda, K., Kubo, M.: An interaction-based language and its typing system. In: Halatsis, C., Maritsas, D., Philokyprou, G., Theodoridis, S. (eds.) PARLE 1994. LNCS, vol. 817, pp. 398–413. Springer, Heidelberg (1994). https://doi.org/10.1007/3-540-58184-7_118

    Chapter  Google Scholar 

  48. Wadler, P.: Propositions as sessions. J. Funct. Program. 24(2–3), 384–418 (2014)

    Article  MathSciNet  Google Scholar 

  49. Walker, D., Crary, K., Morrisett, J.G.: Typed memory management via static capabilities. ACM Trans. Program. Lang. Syst. 22(4), 701–771 (2000)

    Article  Google Scholar 

  50. White, L., Bour, F., Yallop, J.: Modular implicits. In: ML 2014: ACM SIGPLAN ML Family Workshop 2014. Electronic Proceedings in Theoretical Computer Science, vol. 198, pp. 22–63 (2015). https://doi.org/10.4204/EPTCS.198.2

  51. Yoshida, N., Vasconcelos, V.T.: Language primitives and type discipline for structured communication-based programming revisited: two systems for higher-order session communication. Electr. Notes Theor. Comput. Sci 171(4), 73–93 (2007)

    Article  Google Scholar 

Download references

Acknowledgments

We thank anonymous reviewers for many, helpful comments and suggestions. This work was partially supported by JSPS KAKENHI Grant Number 18H03218 and 17K12662.

Author information

Authors and Affiliations

Authors

Corresponding authors

Correspondence to Oleg Kiselyov or Keigo Imai .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2020 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Kiselyov, O., Imai, K. (2020). Session Types Without Sophistry. In: Nakano, K., Sagonas, K. (eds) Functional and Logic Programming. FLOPS 2020. Lecture Notes in Computer Science(), vol 12073. Springer, Cham. https://doi.org/10.1007/978-3-030-59025-3_5

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-59025-3_5

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-59024-6

  • Online ISBN: 978-3-030-59025-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics