Skip to content

A simple library implementation of binary sessions

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE.ml
Notifications You must be signed in to change notification settings

boystrange/FuSe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Simple Library Implementation of Binary Sessions

Overview

FuSe is a lightweight OCaml module that implements the session-based communication primitives in [GayVasconcelos10] and enables session type checking and inference. It works with any out-of-the-box installation of OCaml and supports the following features:

  • delegation
  • equi-recursive session types
  • polymorphic session types
  • context-free session types
  • session types with labeled branches
  • session type inference
  • duality constraints on session type variables
  • hybrid static/dynamic linearity checking
  • session subtyping [GayHole05]
  • higher-order resumption combinators
  • shared channels for session initiation
  • type pretty-printer (external utility)

Installation Instructions

You need OCaml to compile FuSe.

  1. Compile the library and the examples:

    make
  2. Test an example:

    ./examples/Tmath
  3. Test session type inference:

    cd examples
    make Tmath.st

Documentation

Users may refer to the API documentation extracted with ocamldoc in the docs folder and to the papers (see below).

Example

Below is an almost verbatim transcription in OCaml+FuSe of the bookshop example found in [GayVasconcelos10].

module Session = Session.Bare

let rec shopLoop s order =
  match Session.branch s with
  | `Add s -> let book, s = Session.receive s in
              shopLoop s (book :: order)
  | `CheckOut s -> let card, s = Session.receive s in
                   let address, s = Session.receive s in
                   Session.close s

let shop shopAccess =
  shopLoop (Service.accept shopAccess) []

let isChildrensBook book = true

let voucher card address c book =
  let c = if isChildrensBook book then
            let c = Session.select (fun x -> `Add x) c in
            Session.send book c
          else c in
  let c = Session.select (fun x -> `CheckOut x) c in
  let c = Session.send card c in
  let c = Session.send address c in
  Session.close c;
  book

let mother card address shopAccess sonAccess book =
  let c = Service.request shopAccess in
  let c = Session.select (fun x -> `Add x) c in
  let c = Session.send book c in
  let s = Service.request sonAccess in
  let s = Session.send (voucher card address c) s in
  let sonBook, s = Session.receive s in
  Session.close s

let son sonAccess book =
  let s = Service.accept sonAccess in
  let f, s = Session.receive s in
  let s = Session.send (f book) s in
  Session.close s

let _ =
  let mCard = "0123 4567 7654 3210" in
  let mAddress = "17 session type rd" in
  let mBook = "Life of Ada Lovelace" in
  let sBook = "Types and programming languages" in
  let shopAccess = Service.create () in
  let sonAccess = Service.create () in
  let _ = Thread.create shop shopAccess in
  let _ = Thread.create (son sonAccess) sBook in
  mother mCard mAddress shopAccess sonAccess mBook

Here are the (session) types inferred by OCaml, pretty printed in a more readable form by the rosetta utility that accompanies the library. Note the amount of parametric polymorphism compared to the typing of the example as given in [GayVasconcelos10].

val shopLoop : rec X.&[ Add: ?α.X | CheckOut: ?β.?γ ] → α listunit
val shop : rec X.&[ Add: ?α.X | CheckOut: ?β.?γ ] Service.tunit
val isChildrensBook : α → bool
val voucher : α → β → rec X.⊕[ Add: !γ.X | CheckOut: !α.!β ] → γ → γ
val mother : α → β → &[ Add: ?γ.rec X.&[ Add: ?δ.X | CheckOut: ?α.?β ] ] Service.t →
             ?(δ → δ).!ε Service.t → γ → unit
val son : ?(α → β).!β Service.t → α → unit

Bibliography

[GayHole05]: Simon J. Gay and Malcolm Hole: Subtyping for session types in the pi calculus, Acta Informatica, 2005.

[GayVasconcelos10]: Simon J. Gay, Vasco T. Vasconcelos, Linear type theory for asynchronous session types, Journal of Functional Programming, 2010.

[Padovani17A]: Luca Padovani: A Simple Library Implementation of Binary Sessions, Journal of Functional Programming, 2017.

[Padovani17B]: Luca Padovani: Context-Free Session Type Inference, Proceedings of ESOP'17, 2017.

[ThiemannVasconcelos16]: Peter Thiemann and Vasco T. Vasconcelos: Context-Free Session Types, Proceedings of ICFP'16, 2016.

About

A simple library implementation of binary sessions

Topics

Resources

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE.ml

Stars

Watchers

Forks