Session-ocaml: A session-based library with polarities and lenses

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 including delegations. We introduce a notational extension to enhance the session linearity for integrating the session types into the functional programming style. We show applications of session-ocaml to a travel agency use case and an SMTP protocol implementation. Furthermore, we evaluate the performance of on a number of benchmarks.

[1]  Nate Foster,et al.  Combinators for bi-directional tree transformations: a linguistic approach to the view update problem , 2005, POPL '05.

[2]  Davide Sangiorgi,et al.  Session types revisited , 2012, PPDP.

[3]  Luca Padovani,et al.  Chaperone contracts for higher-order sessions , 2017, Proc. ACM Program. Lang..

[4]  Riccardo Pucella,et al.  Haskell session types with (almost) no class , 2008, Haskell '08.

[5]  Peter Thiemann,et al.  An Implementation of Session Types , 2004, PADL.

[6]  Nobuko Yoshida,et al.  Lightweight Session Programming in Scala , 2016, ECOOP.

[7]  Philip Wadler Propositions as sessions , 2012, ICFP '12.

[8]  Nobuko Yoshida,et al.  Hybrid Session Verification Through Endpoint API Generation , 2016, FASE.

[9]  Dominic A. Orchard,et al.  Session Types with Linearity in Haskell , 2017 .

[10]  Vasco Thudichum Vasconcelos,et al.  Linear type theory for asynchronous session types , 2009, Journal of Functional Programming.

[11]  Robin Milner,et al.  Communicating and mobile systems - the Pi-calculus , 1999 .

[12]  Nobuko Yoshida,et al.  Language Primitives and Type Discipline for Structured Communication-Based Programming Revisited: Two Systems for Higher-Order Session Communication , 2007, Electron. Notes Theor. Comput. Sci..

[13]  Nobuko Yoshida,et al.  Session-ocaml: A Session-Based Library with Polarities and Lenses , 2017, COORDINATION.

[14]  Luca Padovani Context-Free Session Type Inference , 2017, ESOP.

[15]  Nobuko Yoshida,et al.  Multiparty asynchronous session types , 2008, POPL '08.

[16]  Nobuko Yoshida,et al.  Effects as sessions, sessions as effects , 2016, POPL.

[17]  Nobuko Yoshida,et al.  Explicit Connection Actions in Multiparty Session Types , 2017, FASE.

[18]  Luca Padovani,et al.  A simple library implementation of binary sessions* , 2016, Journal of Functional Programming.

[19]  Sam Lindley,et al.  Embedding session types in Haskell , 2016, Haskell.

[20]  Simon Peyton Jones,et al.  Type classes: an exploration of the design space , 1997 .

[21]  Nicolas Wu,et al.  Profunctor Optics: Modular Data Accessors , 2017, Art Sci. Eng. Program..

[22]  Jeff Polakow Embedding a full linear Lambda calculus in Haskell , 2015, Haskell.

[23]  Nobuko Yoshida,et al.  Protocols by Default - Safe MPI Code Generation Based on Session Types , 2015, CC.

[24]  Peter Thiemann,et al.  Context-free session types , 2016, ICFP.

[25]  Nobuko Yoshida,et al.  Session-Based Distributed Programming in Java , 2008, ECOOP.

[26]  Yaron Minsky OCaml for the masses , 2011, CACM.

[27]  Andy Gill,et al.  The constrained-monad problem , 2013, ICFP.

[28]  Simon J. Gay,et al.  Subtyping for session types in the pi calculus , 2005, Acta Informatica.

[29]  Mark P. Jones,et al.  Type Classes with Functional Dependencies , 2000, ESOP.

[30]  Kiyoshi Agusa,et al.  Session Type Inference in Haskell , 2011, PLACES.

[31]  Robert Atkey,et al.  Parameterised notions of computation , 2006, J. Funct. Program..

[32]  Ken Friis Larsen,et al.  Session types for Rust , 2015, WGP@ICFP.

[33]  Jérôme Vouillon,et al.  Lwt: a cooperative thread library , 2008, ML '08.

[34]  Naoki Kobayashi,et al.  Type Systems for Concurrent Programs , 2002, 10th Anniversary Colloquium of UNU/IIST.

[35]  Jeremy Yallop,et al.  Modular implicits , 2014, ML/OCaml.

[36]  Gul A. Agha,et al.  Parameterized, concurrent session types for asynchronous multi-actor interactions , 2016, Sci. Comput. Program..

[37]  Vasco Thudichum Vasconcelos,et al.  Language Primitives and Type Discipline for Structured Communication-Based Programming Revisited: Two Systems for Higher-Order Session Communication , 1998, SecReT@ICALP.