2018-07-25 21:26:47 +00:00
|
|
|
#lang typed/syndicate/roles
|
|
|
|
|
2018-07-30 21:00:42 +00:00
|
|
|
;; Expected Output
|
|
|
|
;; 0
|
|
|
|
;; 70
|
2019-01-25 15:51:46 +00:00
|
|
|
;; #f
|
2018-07-30 21:00:42 +00:00
|
|
|
|
2018-07-25 21:26:47 +00:00
|
|
|
(define-constructor (account balance)
|
|
|
|
#:type-constructor AccountT
|
|
|
|
#:with Account (AccountT Int)
|
|
|
|
#:with AccountRequest (AccountT ★/t))
|
|
|
|
|
|
|
|
(define-constructor (deposit amount)
|
|
|
|
#:type-constructor DepositT
|
|
|
|
#:with Deposit (DepositT Int)
|
|
|
|
#:with DepositRequest (DepositT ★/t))
|
|
|
|
|
|
|
|
(define-type-alias ds-type
|
|
|
|
(U Account
|
|
|
|
(Observe AccountRequest)
|
|
|
|
(Observe (Observe AccountRequest))
|
|
|
|
Deposit
|
|
|
|
(Observe DepositRequest)
|
|
|
|
(Observe (Observe DepositRequest))))
|
|
|
|
|
2018-09-10 20:24:44 +00:00
|
|
|
(define-type-alias account-manager-role
|
|
|
|
(Role (account-manager)
|
|
|
|
(Shares Account)
|
|
|
|
(Reacts (Know (Deposit Int)))))
|
|
|
|
|
|
|
|
(define-type-alias client-role
|
|
|
|
(Role (client)
|
|
|
|
(Reacts (Know Account))))
|
|
|
|
|
2019-01-25 15:51:46 +00:00
|
|
|
(run-ground-dataspace ds-type
|
2018-07-25 21:26:47 +00:00
|
|
|
|
2018-07-30 15:54:05 +00:00
|
|
|
(spawn ds-type
|
|
|
|
(print-role
|
|
|
|
(start-facet account-manager
|
2018-08-08 19:20:09 +00:00
|
|
|
(field [balance Int 0])
|
2018-07-30 15:54:05 +00:00
|
|
|
(assert (account (ref balance)))
|
|
|
|
(on (asserted (deposit (bind amount Int)))
|
|
|
|
(set! balance (+ (ref balance) amount))))))
|
2018-07-26 21:16:06 +00:00
|
|
|
|
2018-07-30 15:54:05 +00:00
|
|
|
(spawn ds-type
|
|
|
|
(print-role
|
|
|
|
(start-facet observer
|
|
|
|
(on (asserted (account (bind amount Int)))
|
|
|
|
(displayln amount)))))
|
|
|
|
|
|
|
|
(spawn ds-type
|
|
|
|
(print-role
|
|
|
|
(start-facet buyer
|
|
|
|
(on (asserted (observe (deposit discard)))
|
|
|
|
(start-facet deposits
|
|
|
|
(assert (deposit 100))
|
2019-01-25 15:51:46 +00:00
|
|
|
(assert (deposit -30))))))))
|