Advertisement

Session-ocaml: A Session-Based Library with Polarities and Lenses

  • Keigo ImaiEmail author
  • Nobuko Yoshida
  • Shoji Yuen
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 10319)

Abstract

We propose session-ocaml, a novel library for session-typed concurrent/distributed programming in OCaml. Our technique solely relies on parametric polymorphism, which can encode core session type structures with strong static guarantees. Our key ideas are: (1) polarised session types, which give an alternative formulation of duality enabling OCaml to automatically infer an appropriate session type in a session with a reasonable notational overhead; and (2) a parameterised monad with a data structure called ‘slots’ manipulated with lenses, which can statically enforce session linearity and delegations. We show applications of session-ocaml including a travel agency usecase and an SMTP protocol.

Keywords

Type Inference Multiple Session Main Thread Session Type Protocol Type 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Notes

Acknowledgments

We thank Raymond Hu and Dominic Orchard for their comments on an early version of the paper. The third author thanks the JSPS bilateral research with NFSC for fruitful discussion. This work is partially supported by EPSRC projects EP/K034413/1, EP/K011715/1, EP/L00058X/1, EP/N027833/1 and EP/N028201/1; by EU FP7 612985 (UPSCALE), and COST Action IC1405 (RC); by JSPS International Fellowships (S15051), and KAKENHI JP17K12662, JP25280023 and JP17H01722 from JSPS, Japan.

References

  1. 1.
    Atkey, R.: Parameterized notions of computation. J. Funct. Program. 13(3–4), 355–376 (2009)MathSciNetzbMATHGoogle Scholar
  2. 2.
    Charalambides, M., Dinges, P., Agha, G.A.: Parameterized, concurrent session types for asynchronous multi-actor interactions. Sci. Comput. Program. 115–116, 100–126 (2016)CrossRefGoogle Scholar
  3. 3.
    Dardha, O., Giachino, E., Sangiorgi, D.: Session types revisited. In: Proceedings of the 14th Symposium on Principles and Practice of Declarative Programming (PPDP 2012), pp. 139–150. ACM, New York (2012)Google Scholar
  4. 4.
    Garrigue, J.: A mailing-list post (2006). https://groups.google.com/d/msg/fa.caml/GWWtHOP35dI/IsrOze-qVLwJ
  5. 5.
    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). doi: 10.1007/BFb0053567 CrossRefGoogle Scholar
  6. 6.
    Honda, K., Yoshida, N., Carbone, M.: Multiparty asynchronous session types. In: POPL, pp. 273–284. ACM (2008). A full version, JACM, 63(1), No. 9, 67 pages, 2016Google Scholar
  7. 7.
    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). doi: 10.1007/978-3-662-49665-7_24 CrossRefGoogle Scholar
  8. 8.
    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). doi: 10.1007/978-3-662-54494-5_7 CrossRefGoogle Scholar
  9. 9.
    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). doi: 10.1007/978-3-540-70592-5_22 CrossRefGoogle Scholar
  10. 10.
    Imai, K., Yoshida, N., Yuen, S.: Session-ocaml: a session-based library with polarities and lenses. Technical report, Imperial College London (2017, to appear)Google Scholar
  11. 11.
    Imai, K., Yuen, S., Agusa, K.: Session type inference in Haskell. In: Postproceedings of Thrid Workshop on Programming Language Approaches to Concurrency and Communication-cEntric Software (PLACES 2010), vol. 69, pp. 74–91, March 2010Google Scholar
  12. 12.
    Jane Street Developers: Core library documentation (2016). https://ocaml.janestreet.com/ocaml-core/latest/doc/core/
  13. 13.
    Jespersen, T.B.L., Munksgaard, P., Larsen, K.F.: Session types for rust. In: Proceedings of the 11th ACM SIGPLAN Workshop on Generic Programming (WGP 2015), pp. 13–22. ACM (2015)Google Scholar
  14. 14.
    Jones, M.P.: Type classes with functional dependencies. In: Smolka, G. (ed.) ESOP 2000. LNCS, vol. 1782, pp. 230–244. Springer, Heidelberg (2000). doi: 10.1007/3-540-46425-5_15 CrossRefGoogle Scholar
  15. 15.
    Kmett, E.: Lenses, folds and traversals (2012). http://lens.github.io/
  16. 16.
    Lindley, S., Morris, J.G.: Embedding session types in Haskell. In: Proceedings of the 9th International Symposium on Haskell (Haskell 2016), pp. 133–145. ACM (2016)Google Scholar
  17. 17.
    Milner, R.: Communicating and Mobile Systems: The \(\pi \)-Calculus. Cambridge University Press, Cambridge (1999)zbMATHGoogle Scholar
  18. 18.
    Neubauer, M., Thiemann, P.: An implementation of session types. In: Jayaraman, B. (ed.) PADL 2004. LNCS, vol. 3057, pp. 56–70. Springer, Heidelberg (2004). doi: 10.1007/978-3-540-24836-1_5 CrossRefGoogle Scholar
  19. 19.
    Ng, N., Figueiredo Coutinho, J.G., Yoshida, N.: Protocols by default. In: Franke, B. (ed.) CC 2015. LNCS, vol. 9031, pp. 212–232. Springer, Heidelberg (2015). doi: 10.1007/978-3-662-46663-6_11 CrossRefGoogle Scholar
  20. 20.
    Orchard, D., Yoshida, N.: Effects as sessions, sessions as effects. In: 43th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2016), pp. 568–581. ACM (2016)Google Scholar
  21. 21.
    Orchard, D., Yoshida, N.: Sessions types with linearity in Haskell. In: Gay, S.J., Ravara, A. (eds.) Behavioural Types: From Theory to Tools. River Publishers (2017)Google Scholar
  22. 22.
    Padovani, L.: A simple library implementation of binary sessions. J. Funct. Program. 27, e4 (2016)MathSciNetCrossRefGoogle Scholar
  23. 23.
    Padovani, L.: Context-free session type inference. In: Yang, H. (ed.) ESOP 2017. LNCS, vol. 10201, pp. 804–830. Springer, Heidelberg (2017). doi: 10.1007/978-3-662-54434-1_30 CrossRefGoogle Scholar
  24. 24.
    Pierce, B.C.: Recursive types. In: Types and Programming Languages, Chap. 20, pp. 267–280. MIT Press (2002)Google Scholar
  25. 25.
    Polakow, J.: Embedding a full linear lambda calculus in Haskell. In: Proceedings of the 2015 ACM SIGPLAN Symposium on Haskell (Haskell 2015), pp. 177–188. ACM (2015)Google Scholar
  26. 26.
    Pucella, R., Tov, J.A.: Haskell session types with (almost) no class. In: Proceedings of the First ACM SIGPLAN Symposium on Haskell (Haskell 2008), pp. 25–36. ACM (2008)Google Scholar
  27. 27.
    Scalas, A., Yoshida, N.: Lightweight session programming in scala. In: 30th European Conference on Object-Oriented Programming (ECOOP 2016). LIPIcs, vol. 56, pp. 21:1–21:28. Dagstuhl (2016)Google Scholar
  28. 28.
    Scribble Project homepage. www.scribble.org
  29. 29.
    Thiemann, P., Vasconcelos, V.T.: Context-free session types. In: Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016), pp. 462–475 (2016)Google Scholar
  30. 30.
    Wadler, P.: Propositions as sessions. In: Proceedings of the 17th ACM SIGPLAN International Conference on Functional Programming (ICFP 2012), pp. 273–286. ACM (2012)Google Scholar
  31. 31.
    White, L., Bour, F., Yallop, J.: Modular implicits. In: ACM SIGPLAN ML Family Workshop (ML 2014), vol. 198, pp. 22–63. Electronic Proceedings in Theoretical Computer Science (2015)Google Scholar
  32. 32.
    Yoshida, N., Vasconcelos, V.T.: Language primitives and type discipline for structured communication-based programming revisited: two systems for higher-order session communication. Electron. Notes Theor. Comput. Sci. 171(4), 73–93 (2007)CrossRefGoogle Scholar

Copyright information

© IFIP International Federation for Information Processing 2017

Authors and Affiliations

  1. 1.Gifu UniversityGifuJapan
  2. 2.Imperial College LondonLondonUK
  3. 3.Nagoya UniversityNagoyaJapan

Personalised recommendations