syndicate-2017/racket/typed/example.rkt

27 lines
1006 B
Racket
Raw Normal View History

2017-10-18 14:57:07 +00:00
#lang typed/syndicate
2017-11-15 16:56:12 +00:00
(define-type-alias ds-type
(U (Observe (Tuple String )) (Tuple String Int)))
2017-10-18 14:57:07 +00:00
2017-11-15 16:56:12 +00:00
(dataspace ds-type
2017-11-03 21:28:00 +00:00
2017-11-15 16:56:12 +00:00
(spawn ds-type
2017-11-03 21:28:00 +00:00
(facet _
2017-11-08 21:24:32 +00:00
(fields [the-thing Int 0])
(assert (tuple "the thing" (ref the-thing)))
(on (asserted (tuple "set thing" (bind new-v Int)))
(set! the-thing new-v))))
2017-11-15 16:56:12 +00:00
(spawn ds-type
2017-12-01 20:53:53 +00:00
(let [k (λ [10 (begin)]
[(bind x Int)
(facet _ (fields)
(assert (tuple "set thing" (+ x 1))))])]
(facet _ (fields)
(on (asserted (tuple "the thing" (bind x Int)))
(k x)))))
2017-11-08 21:24:32 +00:00
2017-11-15 16:56:12 +00:00
(spawn ds-type
2017-11-08 21:24:32 +00:00
(facet _ (fields)
(on (asserted (tuple "the thing" (bind t Int)))
(displayln t)))))