diff --git a/collects/typed-scheme/infer/constraint-structs.ss b/collects/typed-scheme/infer/constraint-structs.ss index ef2bccc281..604c8caa53 100644 --- a/collects/typed-scheme/infer/constraint-structs.ss +++ b/collects/typed-scheme/infer/constraint-structs.ss @@ -31,18 +31,6 @@ ;; don't want to rule them out too early (define-struct cset (maps) #:prefab) - -(define (hashof k/c v/c) - (flat-named-contract - (format "#" k/c v/c) - (lambda (h) - (define k/c? (if (flat-contract? k/c) (flat-contract-predicate k/c) k/c)) - (define v/c? (if (flat-contract? v/c) (flat-contract-predicate v/c) v/c)) - (and (hash? h) - (for/and ([(k v) h]) - (and (k/c? k) - (v/c? v))))))) - (provide/contract (struct c ([S Type?] [X symbol?] [T Type?])) (struct dcon ([fixed (listof c?)] [rest (or/c c? false/c)])) (struct dcon-exact ([fixed (listof c?)] [rest c?])) diff --git a/collects/typed-scheme/rep/type-rep.ss b/collects/typed-scheme/rep/type-rep.ss index 0d470720b8..76c0144302 100644 --- a/collects/typed-scheme/rep/type-rep.ss +++ b/collects/typed-scheme/rep/type-rep.ss @@ -146,18 +146,30 @@ [rest (or/c #f Type/c)] [drest (or/c #f (cons/c Type/c (or/c natural-number/c symbol?)))] [kws (listof Keyword?)]) - [#:frees (lambda (free*) - (combine-frees - (append (map (compose flip-variances free*) - (append (if rest (list rest) null) - (map Keyword-ty kws) - dom)) - (match drest - [(cons t (? symbol? bnd)) - (list (fix-bound (flip-variances (free* t)) bnd))] - [(cons t (? number? bnd)) (list (flip-variances (free* t)))] - [#f null]) - (list (free* rng)))))] + [#:frees (combine-frees + (append (map (compose flip-variances free-vars*) + (append (if rest (list rest) null) + (map Keyword-ty kws) + dom)) + (match drest + [(cons t (? symbol? bnd)) + (list (fix-bound (flip-variances (free-vars* t)) bnd))] + [(cons t (? number? bnd)) + (list (flip-variances (free-vars* t)))] + [#f null]) + (list (free-vars* rng)))) + (combine-frees + (append (map (compose flip-variances free-idxs*) + (append (if rest (list rest) null) + (map Keyword-ty kws) + dom)) + (match drest + [(cons t (? symbol? bnd)) + (list (flip-variances (free-idxs* t)))] + [(cons t (? number? bnd)) + (list (fix-bound (flip-variances (free-idxs* t)) bnd))] + [#f null]) + (list (free-idxs* rng))))] [#:fold-rhs (*arr (map type-rec-id dom) (type-rec-id rng) (and rest (type-rec-id rest)) diff --git a/collects/typed-scheme/types/abbrev.ss b/collects/typed-scheme/types/abbrev.ss index 52c43d6fdd..4178ea1a49 100644 --- a/collects/typed-scheme/types/abbrev.ss +++ b/collects/typed-scheme/types/abbrev.ss @@ -172,20 +172,22 @@ (make-Values (list (-result rng filters obj)))) rest drest (sort #:key Keyword-kw kws keyword* - (syntax-rules (:) +(define-syntax (->* stx) + (define-syntax-class c + (pattern x:id #:when (eq? ': (syntax-e #'x)))) + (syntax-parse stx [(_ dom rng) - (make-Function (list (make-arr* dom rng)))] + #'(make-Function (list (make-arr* dom rng)))] [(_ dom rst rng) - (make-Function (list (make-arr* dom rng #:rest rst)))] - [(_ dom rng : filters) - (make-Function (list (make-arr* dom rng #:filters filters)))] - [(_ dom rng : filters : object) - (make-Function (list (make-arr* dom rng #:filters filters #:object object)))] - [(_ dom rst rng : filters) - (make-Function (list (make-arr* dom rng #:rest rst #:filters filters)))] - [(_ dom rst rng : filters : object) - (make-Function (list (make-arr* dom rng #:rest rst #:filters filters #:object object)))])) + #'(make-Function (list (make-arr* dom rng #:rest rst)))] + [(_ dom rng :c filters) + #'(make-Function (list (make-arr* dom rng #:filters filters)))] + [(_ dom rng _:c filters _:c object) + #'(make-Function (list (make-arr* dom rng #:filters filters #:object object)))] + [(_ dom rst rng _:c filters) + #'(make-Function (list (make-arr* dom rng #:rest rst #:filters filters)))] + [(_ dom rst rng _:c filters : object) + #'(make-Function (list (make-arr* dom rng #:rest rst #:filters filters #:object object)))])) (define-syntax (-> stx) (define-syntax-class c diff --git a/collects/typed-scheme/utils/utils.ss b/collects/typed-scheme/utils/utils.ss index 69041a536c..79c0b38517 100644 --- a/collects/typed-scheme/utils/utils.ss +++ b/collects/typed-scheme/utils/utils.ss @@ -23,7 +23,8 @@ at least theoretically. in-syntax symbol-append custom-printer - rep utils typecheck infer env private) + rep utils typecheck infer env private + hashof) (define-syntax (define-requirer stx) (syntax-parse stx @@ -318,4 +319,16 @@ at least theoretically. [(_ nm cnt) (if enable-contracts? (list #'[contracted (nm cnt)]) - (list #'nm))])) \ No newline at end of file + (list #'nm))])) + + +(define (hashof k/c v/c) + (flat-named-contract + (format "#" k/c v/c) + (lambda (h) + (define k/c? (if (flat-contract? k/c) (flat-contract-predicate k/c) k/c)) + (define v/c? (if (flat-contract? v/c) (flat-contract-predicate v/c) v/c)) + (and (hash? h) + (for/and ([(k v) h]) + (and (k/c? k) + (v/c? v))))))) \ No newline at end of file