Allow apply to work on lists with minimum length.

This commit is contained in:
Eric Dobson 2014-04-25 23:07:57 -07:00
parent 347b15661a
commit 3e3e79cf1f
3 changed files with 23 additions and 13 deletions

View File

@ -185,11 +185,11 @@
(eq? (cdr drest) dotted-var) (eq? (cdr drest) dotted-var)
(= (length domain) (length arg-tys)) (= (length domain) (length arg-tys))
(match full-tail-ty (match full-tail-ty
[(Listof: tail-arg-ty) [(List: tail-arg-tys #:tail (Listof: tail-arg-ty))
(infer/vararg (infer/vararg
fixed-vars (list dotted-var) fixed-vars (list dotted-var)
(cons tail-arg-ty arg-tys) (cons tail-arg-ty (append tail-arg-tys arg-tys))
(cons (car drest) domain) (cons (car drest) (append (map (λ _ (car drest)) tail-arg-tys) domain))
rest rest
range)] range)]
[(List: tail-arg-tys) [(List: tail-arg-tys)

View File

@ -28,16 +28,22 @@
(lambda (stx) (lambda (stx)
(syntax-parse stx (syntax-parse stx
[(_ elem-pats) [(_ elem-pats)
#'(app untuple (? values elem-pats))]))) #'(app untuple (? values elem-pats) (Value: '()))]
[(_ elem-pats #:tail tail-pat)
#'(app untuple (? values elem-pats) tail-pat)])))
;; Type/c -> (or/c (values/c #f #f) (values/c (listof Type/c) Type/c)))
;; Returns the prefix of types that are consed on to the last type (a non finite-pair type).
;; The last type may contain pairs if it is a list type.
(define (untuple t) (define (untuple t)
(let loop ((t t) (seen (set))) (let loop ((t t) (seen (set)))
(and (not (set-member? seen (Type-seq t))) (if (not (set-member? seen (Type-seq t)))
(match (resolve t) (match (resolve t)
[(Value: '()) null] [(Pair: a b)
[(Pair: a b) (cond [(loop b (set-add seen (Type-seq t))) => (lambda (l) (cons a l))] (define-values (elems tail) (loop b (set-add seen (Type-seq t))))
[else #f])] (values (cons a elems) tail)]
[_ #f])))) [_ (values null t)])
(values null t))))
(define-match-expander MListof: (define-match-expander MListof:
(lambda (stx) (lambda (stx)

View File

@ -2851,7 +2851,13 @@
(let: ([f : (All (b ...) (Any ... b -> Any)) (lambda x 'x)]) (let: ([f : (All (b ...) (Any ... b -> Any)) (lambda x 'x)])
(lambda xs (apply f xs))) (lambda xs (apply f xs)))
#:ret (ret (->* (list) Univ Univ)) #:ret (ret (->* (list) Univ Univ))
#:expected (ret (->* (list) Univ Univ))] #:expected (ret (->* (list) Univ Univ))]
[tc-e
(let: ([f : (All (b ...) (Any ... b -> Any)) (lambda x 'x)])
(lambda xs (apply f (ann (cons 'y xs) (cons Symbol (Listof Any))))))
#:ret (ret (->* (list) Univ Univ))
#:expected (ret (->* (list) Univ Univ))]
[tc-e [tc-e
(let () (let ()
@ -2878,8 +2884,6 @@
-Symbol -Symbol
#:expected (ret -Symbol)] #:expected (ret -Symbol)]
) )
(test-suite (test-suite
"tc-literal tests" "tc-literal tests"