Add an easy type to variable-mapping? and remove the untyped section.
This commit is contained in:
parent
bd6c62e3eb
commit
f62d53ed8f
1 changed files with 12 additions and 23 deletions
35
utils.rkt
35
utils.rkt
|
@ -26,7 +26,9 @@
|
||||||
collect-by-key/sets ht-values/list->set hash->list/ordered
|
collect-by-key/sets ht-values/list->set hash->list/ordered
|
||||||
multi-split-at lists-transpose in-random cartesian-product-2/stream
|
multi-split-at lists-transpose in-random cartesian-product-2/stream
|
||||||
cartesian-product/stream boolean-power boolean-power/stream any->01
|
cartesian-product/stream boolean-power boolean-power/stream any->01
|
||||||
01->boolean)
|
01->boolean
|
||||||
|
|
||||||
|
variable-mapping?)
|
||||||
|
|
||||||
(define-type Variable Symbol)
|
(define-type Variable Symbol)
|
||||||
(define-type (VariableMapping A) (Immutable-HashTable Variable A))
|
(define-type (VariableMapping A) (Immutable-HashTable Variable A))
|
||||||
|
@ -560,6 +562,13 @@
|
||||||
(test-case "01->boolean"
|
(test-case "01->boolean"
|
||||||
(check-equal? (01->boolean 0) #f)
|
(check-equal? (01->boolean 0) #f)
|
||||||
(check-equal? (01->boolean 1) #t)))
|
(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)
|
(require 'typed)
|
||||||
|
@ -572,26 +581,6 @@
|
||||||
collect-by-key/sets ht-values/list->set hash->list/ordered
|
collect-by-key/sets ht-values/list->set hash->list/ordered
|
||||||
multi-split-at lists-transpose in-random cartesian-product-2/stream
|
multi-split-at lists-transpose in-random cartesian-product-2/stream
|
||||||
cartesian-product/stream boolean-power boolean-power/stream any->01
|
cartesian-product/stream boolean-power boolean-power/stream any->01
|
||||||
01->boolean)
|
01->boolean
|
||||||
|
|
||||||
;;; Untyped section.
|
variable-mapping?)
|
||||||
|
|
||||||
(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)))
|
|
||||||
|
|
Loading…
Reference in a new issue