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
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsNotes
- 1.
- 2.
- 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.
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.
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.
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.
Ours and are called and in [51] (we changed the names to avoid association with exceptions).
- 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.
That tutorial paper also compares canonical structures to related approaches, in particular, implicits and type classes.
References
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
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
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
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
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
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)
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
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
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)
Furuse, J.: Typeful PPX and value implicits. In: OCaml 2015: The OCaml Users and Developers Workshop (2015). https://bitbucket.org/camlspotter/ppx_implicits
Garrigue, J.: Safeio (a mailing-list post) (2006). https://github.com/garrigue/safeio
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
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
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
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
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
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
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
Igarashi, A., Kobayashi, N.: Resource usage analysis. ACM Trans. Program. Lang. Syst. 27(2), 264–313 (2005)
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
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
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
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
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
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
Kiselyov, O.: Reconciling Abstraction with High Performance: A MetaOCaml approach. Foundations and Trends in Programming Languages, Now Publishers (2018)
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
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
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
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
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
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
Lindley, S., Morris, J.G.: Lightweight Functional Session Types (2017). In [45 §12]
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
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
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
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
Orchard, D., Yoshida, N.: Session Types with Linearity in Haskell (2017). In [45 §10]
Padovani, L.: A simple library implementation of binary sessions. J. Func. Program. 27, e4 (2016)
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
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
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/
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
Scribble: Scribble home page (2019). http://www.scribble.org
Simon Gay, A.R. (ed.): Behavioural Types: from Theory to Tools. River Publisher (2017). https://www.riverpublishers.com/research_details.php?book_id=439
Strom, R.E., Yellin, D.M.: Extending typestate checking using conditional liveness analysis. IEEE Trans. Softw. Eng. 19(5), 478–485 (1993)
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
Wadler, P.: Propositions as sessions. J. Funct. Program. 24(2–3), 384–418 (2014)
Walker, D., Crary, K., Morrisett, J.G.: Typed memory management via static capabilities. ACM Trans. Program. Lang. Syst. 22(4), 701–771 (2000)
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
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)
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
Corresponding authors
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2020 Springer Nature Switzerland AG
About this paper
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)