File tree Expand file tree Collapse file tree 3 files changed +55
-9
lines changed
typed-racket-lib/typed-racket
typed-racket-test/succeed Expand file tree Collapse file tree 3 files changed +55
-9
lines changed Original file line number Diff line number Diff line change 1111 [->* t:->*]
1212 [one-of/c t:one-of/c])
1313 (private type-annotation syntax-properties)
14- (types resolve type-table)
14+ (types resolve type-table subtype )
1515 (typecheck signatures tc-metafunctions tc-subst)
1616 (env lexical-env tvar-env index-env scoped-tvar-env)
1717 (utils tc-utils)
639639 (match expected
640640 [(tc-result1:(? DepFun? dep-fun-ty))
641641 (tc/dep-lambda formalss bodies dep-fun-ty)]
642- [_ (make-Fun
643- (tc/mono-lambda
644- (for/list ([f (in-syntax formalss)]
645- [b (in-syntax bodies)])
646- (cons (make-formals f not-in-poly) b))
647- expected))]))
642+ [_
643+ (define arrs (tc/mono-lambda
644+ (for/list ([f (in-syntax formalss)]
645+ [b (in-syntax bodies)])
646+ (cons (make-formals f not-in-poly) b))
647+ expected))
648+
649+ (define (maybe-new-arrow arrs)
650+ (append arrs (match arrs
651+ [(or (? empty?) (list _ )) null]
652+ [(app last (Arrow: dom (and (Rest: (list ty tys ... )) rst) kws rng))
653+ (define new-doms (dropf-right dom (lambda (x) (subtype ty x))))
654+ (if (equal? (length new-doms) dom)
655+ null
656+ (list (make-Arrow new-doms
657+ rst
658+ kws
659+ rng)))]
660+ [_ null])))
661+ (define arrs^ (maybe-new-arrow arrs))
662+ (make-Fun arrs^)]))
663+
648664
649665(define (plambda-prop stx)
650666 (define d (plambda-property stx))
Original file line number Diff line number Diff line change 77(require "../utils/utils.rkt "
88 (utils prefab identifier)
99 racket/list
10+ racket/lazy-require
1011 syntax/id-set
1112 racket/match
1213 (prefix-in c: (contract-req))
2425
2526 (for-syntax racket/base syntax/parse))
2627
28+ (lazy-require ("subtype.rkt " (subtype)))
2729(provide (all-defined-out )
2830 (all-from-out "base-abbrev.rkt " "match-expanders.rkt " ))
2931
188190(define/decl -false-propset (-PS -ff -tt))
189191
190192(define (opt-fn args opt-args result #:rest [rest #f ] #:kws [kws null])
191- (apply cl->* (for/list ([i (in-range (add1 (length opt-args)))])
193+ (define ret (for/list ([i (in-range (add1 (length opt-args)))])
192194 (make-Fun (list (-Arrow (append args (take opt-args i))
193195 result ;; only the LAST arrow gets the rest arg
194196 #:rest (and (= i (length opt-args)) rest)
195- #:kws kws))))))
197+ #:kws kws)))))
198+ (define ret^ (append ret (cond
199+ [rest
200+ (match-define (Rest: (list ty tys ... )) rest)
201+ (list (make-Fun (list (-Arrow
202+ (dropf-right opt-args (lambda (x) (subtype ty x)))
203+ result
204+ #:rest rest
205+ #:kws kws))))]
206+ [else null])))
207+ (apply cl->* ret^))
196208
197209(define-syntax-rule (->opt args ... [opt ... ] res)
198210 (opt-fn (list args ... ) (list opt ... ) res))
Original file line number Diff line number Diff line change 1+ #lang typed/racket
2+
3+ (: bar (-> (-> Natural * Any) Any))
4+ (define (bar f)
5+ 'any )
6+
7+ (: foo (-> (->* () (Integer Integer) #:rest Natural Any)
8+ Any))
9+ (define (foo f)
10+ (bar f))
11+
12+ (: foo^ (-> Any * Any))
13+ (define foo^
14+ (case-lambda
15+ [() 'one ]
16+ [(a) 'two ]
17+ [(a b . cs) 'three ]))
18+
You can’t perform that action at this time.
0 commit comments