Typed Syndicate
(require typed/syndicate/roles) | package: syndicate-classic |
1 Overview
2 Types
syntax
syntax
syntax
syntax
syntax
syntax
(U type ...)
syntax
syntax
syntax
syntax
(Bind type)
syntax
syntax
(Role (x) type ...)
syntax
(Stop X type ...)
syntax
(Field type)
syntax
(Shares type)
syntax
(Reacts EventDesc type ...)
EventDesc = OnStart | OnStart | (Asserted event-type) | (Retracted event-type)
syntax
(Actor type)
syntax
(ActorWithRole comm-type behavior-type)
syntax
(Sends type)
syntax
(Realize type)
syntax
(Tuple type ...)
syntax
(AssertionSet type)
syntax
(∀ (X ...) type)
syntax
(→ type ... (Computation (Value result-type) (Endpoints ep-type ...) (Roles role-type ...) (Spawns spawn-type ...)))
syntax
(→fn type-in ... type-out)
syntax
(proc maybe-quantifiers type-in ... maybe-arrow type-out maybe-endpoints maybe-roles maybe-spawns)
maybe-quantifiers =
| #:forall (X ...) maybe-arrow =
| → | -> maybe-endpoints =
| #:endpoints (e ...) maybe-roles =
| #:roles (r ...) maybe-spawns =
| #:spawns (s ...)
syntax
syntax
syntax
syntax
syntax
3 User Defined Types
syntax
(define-type-alias id type)
(define-type-alias (ty-cons-id arg-id ...) type)
syntax
(define-constructor (ctor-id slot-id ...) maybe-type-ctor maybe-alias ...)
maybe-type-ctor =
| #:type-constructor type-ctor-id maybe-alias =
| #:with alias alias-body
When a type-ctor-id is provided, the type of such structures is (type-ctor-id type ...), where each type describes the value of the corresponding slot. When not provided, the type constructor is named by appending "/t" to ctor-id.
Each alias and alias-body creates an instance of define-type-alias.
syntax
(define-constructor* (ctor-id : type-ctor-id slot-id ...) maybe-alias ...)
syntax
(assertion-struct ctor-id : type-ctor-id (slot-id ...))
syntax
(message-struct ctor-id : type-ctor-id (slot-id ...))
4 Actor Forms
syntax
(run-ground-dataspace type expr ...)
syntax
(spawn maybe-type s)
maybe-type =
| type
syntax
(dataspace type expr ...)
syntax
(start-facet id maybe-spec expr ...+)
maybe-spec =
| #:implements type | #:includes-behavior type
syntax
(stop id expr ...)
syntax
(on event-description body ...+)
event-description = start | stop | (message pattern) | (asserted pattern) | (retracted pattern) pattern = _ | ($ id type) | ($ id) | $id | $id:type | (ctor pattern ...) | expr
_ matches anything.
($ id type) matches any value and binds it to id with assumed type type.
($ id) is like ($ id type), but attempts to use the current communication type to fill in the type of potential matches. May raise an error if no suitable communication type is in scope.
(? pred pattern) matches values where (pred val) is not #f and that match pattern.
$id:type is shorthand for ($ id type).
$id is shorthand for ($ id).
(ctor pat ...) matches values built by applying the constructor ctor to values matching pat .... ctor is usually a struct name.
expr patterns match values that are equal? to expr.
syntax
(on-start expr ...+)
syntax
(on-stop expr ...+)
syntax
(assert expr)
syntax
(know expr)
syntax
(send! expr)
syntax
(realize! expr)
syntax
(field [id maybe-type expr] ...)
maybe-type =
| type | : type
syntax
(ref id)
syntax
(set! id expr)
syntax
(begin/dataflow expr ...+)
syntax
(during pattern expr ...+)
syntax
(during/spawn pattern expr ...+)
syntax
(define/query-value name absent-expr pattern expr maybe-on-add maybe-on-remove)
maybe-on-add =
| #:on-add on-add-expr maybe-on-remove =
| #:on-remove on-remove-expr
syntax
(define/query-set name pattern expr maybe-on-add maybe-on-remove)
maybe-on-add =
| #:on-add on-add-expr maybe-on-remove =
| #:on-remove on-remove-expr
syntax
(define/query-hash name pattern key-expr value-expr maybe-on-add maybe-on-remove)
maybe-on-add =
| #:on-add on-add-expr maybe-on-remove =
| #:on-remove on-remove-expr
syntax
(define/dataflow name maybe-type expr)
maybe-type =
| type
5 Expressions
syntax
(if test-expr then-expr else-expr)
syntax
(when test-expr expr)
syntax
(unless test-expr expr)
syntax
(let ([id expr] ...) body ...+)
syntax
(let* ([id expr] ...) body ...+)
syntax
(lambda ([x opt-: type] ...) expr ...+)
opt-: =
| :
syntax
syntax
(Λ (X ...) expr)
syntax
(inst expr type ...)
syntax
(define id : type expr)
(define id expr) (define (id [arg-id opt-: arg-type] ... opt-res-ty) expr ...+) (define (∀ (X ...) (id [arg-id opt-: arg-type] ... opt-res-ty)) expr ...+)
opt-: =
| : opt-res-ty =
| arr res-type arr = → | ->
syntax
(define-tuple (id ...) expr)
syntax
(match-define pattern expr)
syntax
(begin expr ...+)
syntax
(block expr ...+)
syntax
(match expr [pattern body-expr ...+] ...+)
syntax
(tuple expr ...)
syntax
(select i expr)
value
syntax
(error format-expr arg-expr ...)
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
syntax
(/ e1 e2)
syntax
(and e ...)
syntax
(or e ...)
syntax
(equal? e1 e2)
syntax
(displayln e)
syntax
(printf fmt-expr val-expr ...)
syntax
(~a e ...)
syntax
(for/fold ([acc-id maybe-:ty acc-expr] ...+) (for-clause ...) body-expr ...+)
maybe-:ty =
| : acc-type for-clause = [id seq-expr] | [id : type seq-expr] | [(k-id v-id) hash-expr] | #:when test-expr | #:unless test-expr | #:break test-expr
When more than one acc-id is used, the body of the loop must evaluate to a tuple with one value for each accumulator, with the final tuple also being the result of the entire expression.
Each seq-expr should be of type Sequence, though expressions of type List and Set are automatically converted.
syntax
(for/list (for-clause ...) body ...+)
syntax
(for/set (for-clause ...) body ...+)
syntax
(for/sum (for-clause ...) body ...+)
syntax
(for (for-clause ...) body ...+)
syntax
(for/first (for-clause ...) body ...+)
Unlike racket:for/first, for/first returns a Maybe value to indicate success/failure.
6 Require & Provide
syntax
(struct-out ctor-id)
6.1 Requiring From Outside Typed Syndicate
syntax
(require/typed lib clause ...)
clause = [id : type] | opaque opaque = [#:opaque type-name] | [#:opaque type-name #:arity op arity-nat] opaque = = | > | >=
Note that unlike Typed Racket, Typed Syndicate does not attach contracts to imported bindings.
An #:opaque declaration defines a type type-name (or, in the #:arity case, a type constructor) that may be used to describe imports but otherwise has no other operations.
syntax
(require-struct ctor-id #:as ty-ctor-id #:from lib maybe-omit-accs)
maybe-omit-accs =
| #:omit-accs
Unless #:omit-accs is specified, defines the accessor functions for the struct.
7 Builtin Data Structures
7.1 Lists
syntax
(List type)
value
value
value
value
value
value
value
value
value
value
value
value
value
value
value
syntax
(list e ...)
7.2 Sets
syntax
(Set type)
syntax
(set e ...)
syntax
(set-union st ...+)
syntax
(set-intersect st ...+)
syntax
(set-subtract st ...+)
value
value
set-empty? : (∀ (X) (→fn (Set X) Bool))
value
value
value
set-remove : (∀ (X) (→fn (Set X) X (Set X)))
value
set-member? : (∀ (X) (→fn (Set X) X Bool))
value
value
7.3 Hashes
syntax
(Hash key-type value-type)
syntax
(hash key val ... ...)
value
value
value
hash-ref/failure : (∀ (K V) (→fn (Hash K V) K V V))
value
hash-empty? : (∀ (K V) (→fn (Hash K V) Bool))
value
hash-has-key? : (∀ (K V) (→fn (Hash K V) K Bool))
value
hash-count : (∀ (K V) (→fn (Hash K V) Int))
value
hash-update : (∀ (K V) (→fn (Hash K V) K (→fn V V) (Hash K V)))
value
: (∀ (K V) (→fn (Hash K V) K (→fn V V) V (Hash K V)))
value
hash-remove : (∀ (K V) (→fn (Hash K V) K (Hash K V)))
value
hash-map : (∀ (K V R) (→fn (Hash K V) (→fn K V R) (List R)))
value
value
hash-values : (∀ (K V) (→fn (Hash K V) (List V)))
value
: (∀ (K1 V1 K2 V2) (→fn (Hash K1 V1) (Hash K2 V2) (Hash (U K1 K2) (U V1 V2))))
value
: (∀ (K V) (→fn (Hash K V) (Hash K V) (→fn V V V) (Hash K V)))
value
: (∀ (K1 V1 K2 V2) (→fn (Hash K1 V1) (Hash K2 V2) Bool))
7.4 Sequences
syntax
(Sequence type)
value
empty-sequence : (Sequence ⊥)
value
sequence->list : (∀ (X) (→fn (Sequence X) (List X)))
value
sequence-length : (∀ (X) (→fn (Sequence X) Int))
value
value
value
: (∀ (X) (→fn (Sequence X) (Sequence X) (Sequence X)))
value
: (∀ (A B) (→fn (→fn A B) (Sequence A) (Sequence B)))
value
sequence-andmap : (∀ (X) (→fn (→fn X Bool) (Sequence X) Bool))
value
sequence-ormap : (∀ (X) (→fn (→fn X Bool) (Sequence X) Bool))
value
sequence-fold : (∀ (A B) (→fn (→fn A B A) (Sequence B) A))
value
sequence-count : (∀ (X) (→fn (→fn X Bool) (Sequence X) Int))
value
: (∀ (X) (→fn (→fn X Bool) (Sequence X) (Sequence X)))
value
sequence-add-between : (∀ (X) (→fn (Sequence X) X (Sequence X)))
value
value
in-hash-keys : (∀ (K V) (→fn (Hash K V) (Sequence K)))
value
in-hash-values : (∀ (K V) (→fn (Hash K V) (Sequence V)))
value
value
7.5 Maybe
7.6 Either
struct
v : any?
syntax
(Left type)
struct
v : any?
syntax
(Right type)
syntax
(Either left-type right-type)