Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 52 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,64 +301,62 @@ and open the path printed on the last line of that command.

* Every declaration is a statement (and thereby an expression)



## Example

Here is a variant of the bank account example.

```
actor class Bank(supply : Int) {
private issuer = Issuer();
private reserve = Account(supply);
getIssuer() : async Issuer { return issuer; };
getReserve() : async Account { return reserve; };
};

actor class Issuer() {
hasIssued(account : like Account) : async Bool {
return (account is Account);
};
};

actor class Account(initialBalance : Int) = this {
private var balance : Int = initialBalance;

getBalance() : async Int {
return balance;
};

split(amount : Int) : async Account {
balance -= amount;
return Account(amount);
};

join(account : like Account) {
assert(account is Account);
let amount = balance;
balance := 0;
account.credit(amount, Account);
};

credit(amount : Int, caller : Class) {
assert(this is caller);
balance += amount;
};

isCompatible(account : like Account) : async Bool {
return (account is Account);
};
};
```
/* a simple data structure: mutable, singly linked list */
type List<T> = ?{head: T; var tail: List<T>};

type post = shared Text -> async ();

type IClient = actor {
send: shared Text -> async ();
};

type IServer = actor {
post: Text -> async ();
subscribe: IClient -> async post;
};

actor Server = {
private var clients:List<IClient> = null;

post(message:Text) : async () {
var next = clients;
loop {
switch (next) {
case null return;
case (?l) {
await l.head.send(message);
next := l.tail;
};
};
};
};

subscribe(client:IClient) : async post {
let cs = new { head = client; var tail = clients};
clients := ?cs;
return post;
};
};


actor class Client() = this {
private var name : Text = "";
private var server: ?IServer = null;
go (n:Text,s:IServer) : async () {
name := n;
server := ?s;
let post = await s.subscribe(this);
await post("hello from " # name);
await post("goodbye from " # name);
};
send(msg:Text) : async () {
print name; print " received "; print msg; print "\n";
};
};

Example use:

```
func transfer(sender : Account, receiver : Account, amount : Int) : async () {
let trx = await sender.split(amount);
trx.join(receiver);
};
```

## Syntax

Expand Down
2 changes: 0 additions & 2 deletions design/Syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Productions marked * probably deferred to later versions.
? <typ> option
(shared|class)? <typ-params>? <typ> -> <typ> function
async <typ> future
like <typ> structural expansion
( ((<id> :)? <typ>),* ) tuple
Any top
None bottom
Expand Down Expand Up @@ -74,7 +73,6 @@ Productions marked * probably deferred to later versions.
async <exp> async expression
await <exp> await future (only in async)
assert <exp> assertion
<exp> is <exp> instance-of
<exp> : <typ> type annotation
<dec> declaration (scopes to block)
* throw <exp> raise exception
Expand Down
70 changes: 0 additions & 70 deletions samples/bank.as

This file was deleted.

103 changes: 0 additions & 103 deletions samples/bank.txt

This file was deleted.

2 changes: 1 addition & 1 deletion samples/counter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ testRead()
<= ()
<= ()
-- Finished counter.as:
let Counter : class Int -> Counter = class
let Counter : class Int -> Counter = func
let c : Counter = {dec = func; read = func}
let show : (Text, Int) -> () = func
let showAsync : (Text, async Int) -> () = func
Expand Down
2 changes: 1 addition & 1 deletion samples/quicksort.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ quicksort([8, 3, 9, 5, 2], 0, 4)
<= ()
<= ()
-- Finished quicksort.as:
let QS : class <T>((T, T) -> Int) -> QS<T> = class
let QS : class <T>((T, T) -> Int) -> QS<T> = func
let a : [var Int] = [2, 3, 5, 8, 9]
let cmpi : (Int, Int) -> Int = func
let qs : QS<Int> = {quicksort = func}
Expand Down
4 changes: 1 addition & 3 deletions src/arrange.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ let rec exp e = match e.it with
| AsyncE e -> "AsyncE" $$ [exp e]
| AwaitE e -> "AwaitE" $$ [exp e]
| AssertE e -> "AssertE" $$ [exp e]
| IsE (e1, e2) -> "IsE" $$ [exp e1; exp e2]
| AnnotE (e, t) -> "AnnotE" $$ [exp e; typ t]
| DecE (d, ot) -> "DecE" $$ [dec d ; operator_type !ot]
| OptE e -> "OptE" $$ [exp e]
Expand Down Expand Up @@ -144,8 +143,7 @@ and typ t = match t.it with
| TupT ts -> "TupT" $$ List.map typ ts
| FuncT (s, tbs, at, rt) -> "FuncT" $$ [func_sort s] @ List.map typ_bind tbs @ [ typ at; typ rt]
| AsyncT t -> "AsyncT" $$ [typ t]
| LikeT t -> "LikeT" $$ [typ t]
| ParT t -> "ParT" $$ [typ t]
| ParT t -> "ParT" $$ [typ t]

and id i = Atom i.it
and con_id i = Atom i.it
Expand Down
1 change: 0 additions & 1 deletion src/arrange_ir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ let rec exp e = match e.it with
| AsyncE e -> "AsyncE" $$ [exp e]
| AwaitE e -> "AwaitE" $$ [exp e]
| AssertE e -> "AssertE" $$ [exp e]
| IsE (e1, e2) -> "IsE" $$ [exp e1; exp e2]
| OptE e -> "OptE" $$ [exp e]
| PrimE p -> "PrimE" $$ [Atom p]
| DeclareE (i, t, e1) -> "DeclareE" $$ [id i; exp e1]
Expand Down
1 change: 0 additions & 1 deletion src/arrange_type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ let rec typ (t:Type.typ) = match t with
| Tup ts -> "Tup" $$ List.map typ ts
| Func (s, c, tbs, at, rt) -> "Func" $$ [func_sort s; Atom (control c)] @ List.map typ_bind tbs @ [ "" $$ (List.map typ at); "" $$ (List.map typ rt)]
| Async t -> "Async" $$ [typ t]
| Like t -> "Like" $$ [typ t]
| Mut t -> "Mut" $$ [typ t]
| Class -> Atom "Class"
| Shared -> Atom "Shared"
Expand Down
4 changes: 0 additions & 4 deletions src/async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ let rec t_typ (t:T.typ) =
end
| Opt t -> Opt (t_typ t)
| Async t -> t_async nary (t_typ t)
| Like t -> Like (t_typ t)
| Obj (s, fs) -> Obj (s, List.map t_field fs)
| Mut t -> Mut (t_typ t)
| Class -> Class
Expand Down Expand Up @@ -292,8 +291,6 @@ and t_exp' (exp:exp) =
| AwaitE _ -> assert false
| AssertE exp1 ->
AssertE (t_exp exp1)
| IsE (exp1, exp2) ->
IsE (t_exp exp1, t_exp exp2)
| DeclareE (id, typ, exp1) ->
DeclareE (id, t_typ typ, t_exp exp1)
| DefineE (id, mut ,exp1) ->
Expand Down Expand Up @@ -407,4 +404,3 @@ let transform scope prog =
let prog = t_prog prog in
check_prog scope prog;
prog;

4 changes: 0 additions & 4 deletions src/awaitopt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ and t_exp' context exp' =
| AwaitE _ -> assert false (* an await never has effect T.Triv *)
| AssertE exp1 ->
AssertE (t_exp context exp1)
| IsE (exp1, exp2) ->
IsE (t_exp context exp1, t_exp context exp2)
| DeclareE (id, typ, exp1) ->
DeclareE (id, typ, t_exp context exp1)
| DefineE (id, mut ,exp1) ->
Expand Down Expand Up @@ -417,8 +415,6 @@ and c_exp' context exp k =
)
| AssertE exp1 ->
unary context k (fun v1 -> e (AssertE v1)) exp1
| IsE (exp1, exp2) ->
binary context k (fun v1 v2 -> e (IsE (v1,v2))) exp1 exp2
| DeclareE (id, typ, exp1) ->
unary context k (fun v1 -> e (DeclareE (id, typ, v1))) exp1
| DefineE (id, mut, exp1) ->
Expand Down
Loading