Type apply-rs.

This commit is contained in:
Sergiu Ivanov 2023-08-10 16:19:58 +02:00
parent b29f98105f
commit a51bba870e
2 changed files with 26 additions and 1 deletions

16
rs.rkt
View File

@ -5,7 +5,7 @@
(provide
Species (struct-out reaction) Reaction ReactionName ReactionSystem
make-reaction enabled? list-enabled union-products)
make-reaction enabled? list-enabled union-products apply-rs)
(module+ test
(require typed/rackunit))
@ -77,6 +77,20 @@
(set 'z))
(check-equal? (union-products rs '())
(set))))
(: apply-rs (-> ReactionSystem (Setof Species) (Setof Species)))
(define (apply-rs rs s)
(let ([as (list-enabled rs s)])
(union-products rs as)))
(module+ test
(test-case "apply-rs"
(define rs (hash 'a (make-reaction '(x) '(y) '(z))
'b (make-reaction '(x y) '() '(t))))
(check-equal? (apply-rs rs (set 'x 'y))
(set 't))
(check-equal? (apply-rs rs (set 'x))
(set 'z))))
)
(require graph "utils.rkt" "generic.rkt")

View File

@ -112,6 +112,17 @@ empty set.
'(a b))
]}
@defproc[(apply-rs [rs ReactionSystem] [s (Setof Species)])
(Setof Species)]{
Applies the reaction system @racket[rs] to @racket[s].
@ex[
(let ([rs (hash 'a (make-reaction '(x) '(y) '(z))
'b (make-reaction '(x y) '() '(z)))])
(apply-rs rs (set 'x)))
]}
@section{Org-mode interaction}