Mirage

Type-driven programming for mobile, cloud and desktop applications »
Anil Madhavapeddy

Anil Madhavapeddy
Systems Research Group, 
University of Cambridge
Cloud
Desktop
Mobile
PiCloud
AppEngine
Amazon EC2
> def func():
    do_compute ()

> import cloud
> cloud.call(func)
class Location(db.Model):
    loc = db.GeoPtProperty()
    date = db.DateTimeProperty()
    accuracy = db.FloatProperty()
function (doc) {
  if (doc.Type == "customer")
    emit(doc.name, {name: doc.name });
}
Windows
Linux
MacOS X
Android
iPhone
Background processes
Java or native ARM code
JSON/RPC function call bridge 
No background processes
Objective C only for UI
Push support for incoming messages
type t = {
  name: string;
  age: int option;
  friends: t list;
} with type_of
let type_of_t =
  Rec ("t",
     Dict(
         ("name", `RO, String);
         ("age", `RO, Option(Int 63));
         ("friends", `RO, Enum (Var "t"))
     ))
Type
Value
let me = {
  name="Anil";
  age=Some 30;
  friends: [bob];
}
value_of_t me :
  Ext ("t", 3, 
     Dict(
         ("name", String "Anil");
         ("age", Value (Int 63));
         ("friends",
            Ext("t", 2, 
               Dict(
                  ("name", String "Bob");
                  ("age", Null), ...
ORM
type t = {
  name: string;
  age: int option;
  friends: t list;
} with orm
t_init: string -> (t, [`RW]) Db.t
t_init_ro : string -> (t, [`RO]) Db.t

t_save (t,[`RW]) Db.t -> t -> unit

t_get: ?name:[<`Contains of string
                                  |`Eq of string] ->
                  ?age:[< `Null | `Eq int |
                                 `Gt int  (...) ] 
                  (t, [< `RO|`RW ]) Db.t -> unit

t_delete: (t,[`RW]) Db.t -> t -> unit
type t = 
| Unit                  | Int of Int64
| Bool of bool    | Float of float
| String of string
| Enum of t list
| Tuple of t list
| Dict of (string * t) list
| Sum of (string * t list)
| Null     | Value of t
| Arrow of string
| Rec of (string * int64) * t
| Var of (string * int64)
| Ext of (string * int64) * t
type t = 
| Unit      | Bool
| Float     | Char
| String   | Int of int option
| Enum of t
| Tuple of t list
| Option of t
| Dict of (string * [`RO|`RW] * t) list
| Sum of (string * t list) list
| Rec of string * t    | Var of string
| Ext of string * t
| Arrow of t * t
Shelf
json_of_t : t -> string
t_of_json : string -> t

{ name: "Anil",
   age: 30, 
  friends: [
     { name: "Bob", friends: [] }
   ] 
} 
type t = {
  name: string;
  age: int option;
  friends: t list;
} with json
SQL
CREATE TABLE types (n TEXT, t TEXT);
CREATE TABLE t_friends (
    id INT, next INT, size INT, val INT);
CREATE TABLE t (id, name TEXT 
    age_isset INT, age INT, friends INT); 
CREATE UNIQUE INDEX idx_1 
  ON t_friends (id, next);
CREATE TRIGGER t_friends_clean 
  AFTER UPDATE OF friends ON t (...);
AppEngine
name: java.lang.String
age: java.lang.Integer
friends: ListProperty<t>

Uses Cadmium to convert
OCaml to Java

Loading comments...

Please log in to add your comment.

Report abuse

More presentations by Anil Madhavapeddy

  • Multi-scale, not multicore

    Anil Madhavapeddy on

    Type-driven programming for mobile, cloud and desktop applications

  • Personal Containers

    Anil Madhavapeddy on

    An architecture for securely storing personal data

  • Mirage

    Anil Madhavapeddy on

    Type-driven programming for mobile, cloud and desktop applications