Code Monkey home page Code Monkey logo

fuse's Introduction

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.

fuse's People

Contributors

boystrange avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.