add hash/c stronger
also, bring down below 102 columns
This commit is contained in:
parent
3ad2cb83bb
commit
a9c0c8bccd
|
@ -193,6 +193,22 @@
|
||||||
(ctest #f contract-stronger? (box/c (<=/c 3)) (box/c (<=/c 3) #:immutable #t))
|
(ctest #f contract-stronger? (box/c (<=/c 3)) (box/c (<=/c 3) #:immutable #t))
|
||||||
(ctest #f contract-stronger? (box/c (<=/c 3)) (box/c (<=/c 3) #:immutable #f))
|
(ctest #f contract-stronger? (box/c (<=/c 3)) (box/c (<=/c 3) #:immutable #f))
|
||||||
|
|
||||||
|
(ctest #t contract-stronger? (hash/c integer? symbol?) (hash/c integer? symbol?))
|
||||||
|
(ctest #f contract-stronger? (hash/c integer? symbol?) (hash/c symbol? integer?))
|
||||||
|
(ctest #f contract-stronger? (hash/c (<=/c 2) symbol?) (hash/c (<=/c 3) symbol?))
|
||||||
|
(ctest #t contract-stronger?
|
||||||
|
(hash/c (<=/c 2) symbol? #:immutable #t)
|
||||||
|
(hash/c (<=/c 3) symbol? #:immutable #t))
|
||||||
|
(ctest #f contract-stronger?
|
||||||
|
(hash/c (<=/c 3) symbol? #:immutable #t)
|
||||||
|
(hash/c (<=/c 2) symbol? #:immutable #t))
|
||||||
|
(ctest #t contract-stronger?
|
||||||
|
(hash/c (<=/c 2) symbol? #:immutable #f)
|
||||||
|
(hash/c (<=/c 2) symbol?))
|
||||||
|
(ctest #f contract-stronger?
|
||||||
|
(hash/c (<=/c 2) symbol?)
|
||||||
|
(hash/c (<=/c 2) symbol? #:immutable #f))
|
||||||
|
|
||||||
(contract-eval
|
(contract-eval
|
||||||
`(let ()
|
`(let ()
|
||||||
(define x (flat-rec-contract x (or/c (cons/c x '()) '())))
|
(define x (flat-rec-contract x (or/c (cons/c x '()) '())))
|
||||||
|
|
|
@ -86,9 +86,10 @@
|
||||||
(when (and (not flat?)
|
(when (and (not flat?)
|
||||||
(not (flat-contract? dom-ctc))
|
(not (flat-contract? dom-ctc))
|
||||||
(not (hash-equal? val)))
|
(not (hash-equal? val)))
|
||||||
(raise-blame-error blame val
|
(raise-blame-error
|
||||||
'(expected "equal?-based hash table due to higher-order domain contract" given: "~e")
|
blame val
|
||||||
val))
|
'(expected "equal?-based hash table due to higher-order domain contract" given: "~e")
|
||||||
|
val))
|
||||||
(case immutable
|
(case immutable
|
||||||
[(#t)
|
[(#t)
|
||||||
(unless (immutable? val)
|
(unless (immutable? val)
|
||||||
|
@ -136,6 +137,29 @@
|
||||||
|
|
||||||
(define-struct base-hash/c (dom rng immutable))
|
(define-struct base-hash/c (dom rng immutable))
|
||||||
|
|
||||||
|
(define (hash/c-stronger this that)
|
||||||
|
(define this-dom (base-hash/c-dom this))
|
||||||
|
(define this-rng (base-hash/c-rng this))
|
||||||
|
(define this-immutable (base-hash/c-immutable this))
|
||||||
|
(cond
|
||||||
|
[(base-hash/c? that)
|
||||||
|
(define that-dom (base-hash/c-dom that))
|
||||||
|
(define that-rng (base-hash/c-rng that))
|
||||||
|
(define that-immutable (base-hash/c-immutable that))
|
||||||
|
(cond
|
||||||
|
[(and (equal? this-immutable #t)
|
||||||
|
(equal? that-immutable #t))
|
||||||
|
(and (contract-stronger? this-dom that-dom)
|
||||||
|
(contract-stronger? this-rng that-rng))]
|
||||||
|
[(or (equal? that-immutable 'dont-care)
|
||||||
|
(equal? this-immutable that-immutable))
|
||||||
|
(and (contract-stronger? this-dom that-dom)
|
||||||
|
(contract-stronger? that-dom this-dom)
|
||||||
|
(contract-stronger? this-rng that-rng)
|
||||||
|
(contract-stronger? that-rng this-rng))]
|
||||||
|
[else #f])]
|
||||||
|
[else #f]))
|
||||||
|
|
||||||
(define-struct (flat-hash/c base-hash/c) ()
|
(define-struct (flat-hash/c base-hash/c) ()
|
||||||
#:omit-define-syntaxes
|
#:omit-define-syntaxes
|
||||||
#:property prop:custom-write custom-write-property-proc
|
#:property prop:custom-write custom-write-property-proc
|
||||||
|
@ -143,6 +167,7 @@
|
||||||
(build-flat-contract-property
|
(build-flat-contract-property
|
||||||
#:name hash/c-name
|
#:name hash/c-name
|
||||||
#:first-order hash/c-first-order
|
#:first-order hash/c-first-order
|
||||||
|
#:stronger hash/c-stronger
|
||||||
#:projection
|
#:projection
|
||||||
(λ (ctc)
|
(λ (ctc)
|
||||||
(λ (blame)
|
(λ (blame)
|
||||||
|
@ -202,6 +227,7 @@
|
||||||
(build-chaperone-contract-property
|
(build-chaperone-contract-property
|
||||||
#:name hash/c-name
|
#:name hash/c-name
|
||||||
#:first-order hash/c-first-order
|
#:first-order hash/c-first-order
|
||||||
|
#:stronger hash/c-stronger
|
||||||
#:projection (ho-projection chaperone-hash)))
|
#:projection (ho-projection chaperone-hash)))
|
||||||
|
|
||||||
(define-struct (impersonator-hash/c base-hash/c) ()
|
(define-struct (impersonator-hash/c base-hash/c) ()
|
||||||
|
@ -211,4 +237,5 @@
|
||||||
(build-contract-property
|
(build-contract-property
|
||||||
#:name hash/c-name
|
#:name hash/c-name
|
||||||
#:first-order hash/c-first-order
|
#:first-order hash/c-first-order
|
||||||
|
#:stronger hash/c-stronger
|
||||||
#:projection (ho-projection impersonate-hash)))
|
#:projection (ho-projection impersonate-hash)))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user