From e867a86d4d0c793777fe1abc41a03b17bb7baad1 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Fri, 29 Apr 2022 16:10:36 +0200 Subject: [PATCH] Add the type Domain. --- networks.rkt | 7 ++++--- scribblings/networks.scrbl | 10 +++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/networks.rkt b/networks.rkt index 8f1bf78..441e2d5 100644 --- a/networks.rkt +++ b/networks.rkt @@ -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) diff --git a/scribblings/networks.scrbl b/scribblings/networks.scrbl index 74d6656..582e7ef 100644 --- a/scribblings/networks.scrbl +++ b/scribblings/networks.scrbl @@ -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.