Add an easy type to variable-mapping? and remove the untyped section.

This commit is contained in:
Sergiu Ivanov 2022-03-05 13:29:37 +01:00
parent bd6c62e3eb
commit f62d53ed8f

View file

@ -26,7 +26,9 @@
collect-by-key/sets ht-values/list->set hash->list/ordered
multi-split-at lists-transpose in-random cartesian-product-2/stream
cartesian-product/stream boolean-power boolean-power/stream any->01
01->boolean)
01->boolean
variable-mapping?)
(define-type Variable Symbol)
(define-type (VariableMapping A) (Immutable-HashTable Variable A))
@ -560,6 +562,13 @@
(test-case "01->boolean"
(check-equal? (01->boolean 0) #f)
(check-equal? (01->boolean 1) #t)))
;; TODO: Remove when the other modules are converted to Typed Racket
;; and these contracts are not needed any more.
(: variable-mapping? (-> Any Boolean : HashTableTop))
(define (variable-mapping? dict)
(hash? dict))
)
(require 'typed)
@ -572,26 +581,6 @@
collect-by-key/sets ht-values/list->set hash->list/ordered
multi-split-at lists-transpose in-random cartesian-product-2/stream
cartesian-product/stream boolean-power boolean-power/stream any->01
01->boolean)
01->boolean
;;; Untyped section.
(provide
;; Contracts
(contract-out [variable-mapping? contract?]
[string-variable-mapping? contract?]
[general-pair/c (-> contract? contract? contract?)]))
(module+ test
(require rackunit))
(define (variable-mapping? dict) (hash/c symbol? any/c))
;;; A string variable mapping is a mapping from variables to strings.
(define (string-variable-mapping? dict) (hash/c symbol? string?))
;;; A contract allowing pairs constructed via cons or via list.
(define (general-pair/c key-contract val-contract)
(or/c (list/c key-contract val-contract)
(cons/c key-contract val-contract)))
variable-mapping?)