Add the type Domain.

This commit is contained in:
Sergiu Ivanov 2022-04-29 16:10:36 +02:00
parent be729f6ca8
commit e867a86d4d
2 changed files with 13 additions and 4 deletions

View File

@ -8,21 +8,22 @@
(require typed/rackunit))
(provide
State UpdateFunction DomainMapping
State UpdateFunction Domain DomainMapping
(struct-out network) Network
make-same-domains make-boolean-domains make-boolean-network)
(define-type (State a) (VariableMapping a))
(define-type (UpdateFunction a) (-> (State a) a))
(define-type (DomainMapping a) (VariableMapping (Listof a)))
(define-type (Domain a) (Listof a))
(define-type (DomainMapping a) (VariableMapping (Domain a)))
(struct (a) network ([functions : (VariableMapping (UpdateFunction a))]
[domains : (DomainMapping a)])
#:transparent
#:type-name Network)
(: make-same-domains (All (a) (-> (Listof Variable) (Listof a)
(: make-same-domains (All (a) (-> (Listof Variable) (Domain a)
(DomainMapping a))))
(define (make-same-domains vars domain)
(for/hash ([var vars]) : (DomainMapping a)

View File

@ -41,6 +41,14 @@ state. This is a synonym of the type @racket[(-> (State a) a)].
}
@defform[#:kind "type" (Domain a)]{
A domain which is a subset of the type @racket[a].
@racket[(Domain a)] is a synonym of @racket[(Listof a)].
}
@defform[#:kind "type" (DomainMapping a)]{
A domain mapping is a hash table mapping variables to the lists of values in
@ -80,7 +88,7 @@ The type of the instances of @racket[Network].
@section{Constructing networks}
@defproc[(make-same-domains [vars (Listof Variable)]
[domain (Listof a)])
[domain (Domain a)])
(DomainMapping a)]{
Makes a hash set mapping all variables to a single domain.