syndicate-2017/racket/typed/example.rkt

34 lines
1.4 KiB
Racket
Raw Normal View History

2017-10-18 14:57:07 +00:00
#lang typed/syndicate
2017-11-01 20:09:07 +00:00
#;(require racket/base)
2017-10-18 14:57:07 +00:00
2017-11-03 21:28:00 +00:00
;; really lame how many times I have to write the dataspace type
2017-11-08 22:45:21 +00:00
#;(print-type
2017-11-08 21:24:32 +00:00
(λ [10 (begin)]
[(bind x Int)
(facet _ (fields)
(assert (tuple "set thing" (+ x 1))))]))
2017-11-03 21:28:00 +00:00
2017-11-08 22:45:21 +00:00
(dataspace (U (Observe (Tuple String )) (Tuple String Int))
2017-11-03 21:28:00 +00:00
2017-11-08 21:24:32 +00:00
(spawn (U (Observe (Tuple String )) (Tuple String Int))
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))))
(spawn (U (Observe (Tuple String )) (Tuple String Int))
2017-11-08 22:45:21 +00:00
(let-function [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
(spawn (U (Observe (Tuple String )) (Tuple String Int))
(facet _ (fields)
(on (asserted (tuple "the thing" (bind t Int)))
(displayln t)))))