alms-0.4.9: examples/ex36-session-types-type-error.alms
(* An example with session types, including choice. (Type error) *)
#load "libthread"
#load "libsessiontype"
open SessionType
type 'a protocol = !'a; !'a; ?'a; 1
|+|
!'a; ?'a; 1
let server =
fun c : int protocol dual channel ->
match follow c with
| Left c ->
let (x, c) = recv c in
send c (0 - x);
()
| Right c ->
let (x, c) = recv c in
let (y, c) = recv c in
send c (x + y);
()
let client =
fun c : int protocol channel ->
fun (x : int) (y : int) ->
let c = sel1 c in
let c = send c x in
let c = send c y in
let (r, _) = recv c in
r
let main =
fun (x : int) (y : int) ->
let rv = newRendezvous[int protocol] () in
AThread.fork (fun () -> server (accept rv));
client (request rv) x y
in print (main 3 4)