Allow (All (A) A -> A), dropping pair of parens.

original commit: d4d286d31dce759129c372c9e42bfb37300bf167
This commit is contained in:
Sam Tobin-Hochstadt 2010-06-13 14:35:37 -04:00
parent 3f3e732ac3
commit ae851e41cd
3 changed files with 25 additions and 5 deletions

View File

@ -74,6 +74,11 @@
[(-> (values Number Boolean Number)) (t:-> (-values (list N B N)))]
[(Number -> Number) (t:-> N N)]
[(Number -> Number) (t:-> N N)]
[(All (A) Number -> Number) (-poly (a) (t:-> N N))]
[(All (A) (Number -> Number)) (-poly (a) (t:-> N N))]
[(All (A) A -> A) (-poly (a) (t:-> a a))]
[(All (A) A A) (-poly (a) (t:-> a a))]
[(All (A) (A -> A)) (-poly (a) (t:-> a a))]
;; requires transformer time stuff that doesn't work
#;[(Refinement even?) (make-Refinement #'even?)]
[(Number Number Number Boolean -> Number) (N N N B . t:-> . N)]

View File

@ -51,23 +51,36 @@
#:attr bound (datum->syntax #'i (string->symbol (substring (attribute s) 3)) #'i #'i))
(pattern (~seq _:ddd bound:id)))
(define (parse-all-body s)
(syntax-parse s
[(ty)
(parse-type #'ty)]
[(x ...)
#:fail-unless (= 1 (length
(for/list ([i (syntax->list #'(x ...))]
#:when (and (identifier? i)
(free-identifier=? i #'t:->)))
i)))
#f
(parse-type s)]))
(define (parse-all-type stx parse-type)
;(printf "parse-all-type: ~a ~n" (syntax->datum stx))
(syntax-parse stx #:literals (t:All)
[((~and kw t:All) (vars:id ... v:id dd:ddd) t)
[((~and kw t:All) (vars:id ... v:id dd:ddd) . t)
(let* ([vars (map syntax-e (syntax->list #'(vars ...)))]
[tvars (map make-F vars)]
[v (syntax-e #'v)]
[tv (make-Dotted (make-F v))])
(add-type-name-reference #'kw)
(parameterize ([current-tvars (extend-env (cons v vars) (cons tv tvars) (current-tvars))])
(make-PolyDots (append vars (list v)) (parse-type #'t))))]
[((~and kw t:All) (vars:id ...) t)
(make-PolyDots (append vars (list v)) (parse-all-body #'t))))]
[((~and kw t:All) (vars:id ...) . t)
(let* ([vars (map syntax-e (syntax->list #'(vars ...)))]
[tvars (map make-F vars)])
(add-type-name-reference #'kw)
(parameterize ([current-tvars (extend-env vars tvars (current-tvars))])
(make-Poly vars (parse-type #'t))))]
(make-Poly vars (parse-all-body #'t))))]
[(t:All (_:id ...) _ _ _ ...) (tc-error "All: too many forms in body of All type")]
[(t:All . rest) (tc-error "All: bad syntax")]))

View File

@ -202,7 +202,9 @@ The following base types are parameteric in their type arguments.
@defform/none[(t t1 t2 ...)]{is the instantiation of the parametric type
@racket[t] at types @racket[t1 t2 ...]}
@defform[(All (v ...) t)]{is a parameterization of type @racket[t], with
type variables @racket[v ...]}
type variables @racket[v ...]. If @racket[t] is a function type
constructed with @racket[->], the outer pair of parentheses
around the function type may be omitted.}
@defform[(values t ...)]{is the type of a sequence of multiple values, with
types @racket[t ...]. This can only appear as the return type of a
function.