Type network and add examples.

This commit is contained in:
Sergiu Ivanov 2022-04-28 23:47:37 +02:00
parent 8067f9e7f0
commit 883e845d9d
2 changed files with 40 additions and 12 deletions

View File

@ -4,16 +4,24 @@
(require "utils.rkt" "functions.rkt"
typed/graph racket/random)
(module+ test
(require typed/rackunit))
(provide
State UpdateFunction DomainMapping)
State UpdateFunction DomainMapping
(struct-out network) Network)
(define-type (State a) (VariableMapping a))
(define-type (UpdateFunction a) (-> (State a) a))
(define-type (DomainMapping a) (VariableMapping (Listof a)))
(struct (a) network ([functions : (VariableMapping (UpdateFunction a))]
[domains : (DomainMapping a)])
#:transparent
#:type-name Network)
)
(require 'typed)
(provide)
(require (except-in "utils.rkt" lists-transpose) (submod "utils.rkt" untyped)
@ -183,15 +191,6 @@
;;; values in their domains.
(define domain-mapping/c (hash/c variable? list?))
;;; A network consists of a mapping from its variables to its update
;;; variables, as a well as of a mapping from its variables to
;;; their domains.
;;;
;;; The domain mapping does not have to assign domains to all
;;; variables (e.g., it may be empty), but in this case the functions
;;; which need to know the domains will not work.
(struct network (functions domains) #:transparent)
;;; Builds a network from a given hash table assigning functions to
;;; variables by attributing Boolean domains to every variable.
(define (make-boolean-network funcs)

View File

@ -11,7 +11,7 @@
(parameterize ([sandbox-output 'string]
[sandbox-error-output 'string]
[sandbox-memory-limit 50])
(make-evaluator 'typed/racket #:requires '("networks.rkt"))))
(make-evaluator 'typed/racket #:requires '((submod "networks.rkt" typed)))))
@(define-syntax-rule (ex . args)
(examples #:eval networks-evaluator . args))
@ -48,6 +48,35 @@ their domains.
}
@defstruct*[network ([functions (VariableMapping (UpdateFunction a))]
[domains (DomainMapping a)])]{
A network consists of a mapping from its variables to its update variables, as
a well as of a mapping from its variables to their domains.
Instances of @racket[network] have the type @racket[Network].
}
@defidform[#:kind "type" Network]{
The type of the instances of @racket[Network].
@ex[
(: or-func (UpdateFunction Boolean))
(define (or-func s)
(or (hash-ref s 'a) (hash-ref s 'b)))
(: and-func (UpdateFunction Boolean))
(define (and-func s)
(and (hash-ref s 'a) (hash-ref s 'b)))
(network (hash 'a or-func
'b and-func)
(hash 'a '(#f #t)
'b '(#f #t)))
]}
@section{Syntactic description of networks}
@section{Inferring interaction graphs}