mirage/mirage-lambda

Name: mirage-lambda

Owner: MirageOS

Description: An eDSL for MirageOS apps

Created: 2018-04-09 13:59:57.0

Updated: 2018-05-24 10:12:38.0

Pushed: 2018-05-16 08:00:33.0

Homepage:

Size: 121

Language: OCaml

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

mirage-lambda – an eDSL to ship computation to MirageOS applications

Mirage Lambda allows to describe functions using a monomorphic typed lambda calculus with well-typed host primitives (for instance calls to the MirageOS APIs). A client can use the eDSL to describe the function to execute remotely. The Mirage Lambda API provides ways to parse, print, type, untype and to evaluate these terms. These functions can be used by both the client and the servers to ship code to be run on remotely.

Installation

Mirage Lambda can be installed with opam:

opam install mirage-lambda

If you don't use opam consult the opam file for build instructions.

Documentation

The documentation and API reference is automatically generated by from the source interfaces. It can be consulted online or via odig doc cmdliner.

Example

The factorial can be defined as a ('a, int -> int) Lambda.Expr.t value. The 'a is the of the environment, int -> int is the type of the expression:

 Lambda

fact =
t open Expr in
t main =
let_rec Type.("x", int ** int) Type.int (fun ~context ~return ~continue ->
    let acc = fst context in
    let n = snd context in
    (if_ (n = int 0)
       (return acc)
       (continue (pair (acc * n) (n - int 1))))
  ) in
mbda ("x", Type.int) (main $ (pair (int 1) (var Var.o)))

To ship the code and waiting for a server response:

t u  = Expr.untype fact in      (* Generate an AST *)
t s  = Parsetree.to_string u in (* Pretty-print the AST *)
nd s >>= receive

The lambda server, on the other-side will receive the code, type it, and evaluate it and send the response back:

ceive () >>= fun s ->
t u = parse_exn s in (* Parse *)
t e = typ_exn u in   (* Type *)
t v = eval e in      (* Evaluate *)
nd (string_of_value v)

The server can also defines a list of host function primitives that it can exposes to the clients:

t primitives = [
primitive "string_of_int" [Type.int] Type.string string_of_int
primitive "string_of_float" [Type.float] Type.string string_of_int
in
.
 Exposes the names [string_of_int] and [string_of_float] in the context. *)
t v = parse_exn ~primitives s in
.
Sponsors

        


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.