Add polydots to all things that support it.

Closes PR 13612.
Closes PR 13584.
This commit is contained in:
Eric Dobson 2013-04-03 23:09:04 -07:00
parent fc36c12ce4
commit 2e2ef0b57a
2 changed files with 49 additions and 30 deletions

View File

@ -101,14 +101,15 @@ Type-annotated versions of
@defform/subs[(lambda: formals . body) @defform/subs[(lambda: formals . body)
([formals ([v : t] ...) ([formals ([v : t] ...)
([v : t] ... . [v : t *]) ([v : t] ... v : t *)
([v : t] ... . [v : t ...])])]{ ([v : t] ... v : t ooo bound)])]{
A function of the formal arguments @racket[v], where each formal A function of the formal arguments @racket[v], where each formal
argument has the associated type. If a rest argument is present, then argument has the associated type. If a rest argument is present, then
it has type @racket[(Listof t)].} it has type @racket[(Listof t)].}
@defform[(λ: formals . body)]{ @defform[(λ: formals . body)]{
An alias for the same form using @racket[lambda:].} An alias for the same form using @racket[lambda:].}
@defform[(plambda: (a ...) formals . body)]{ @defform*[[(plambda: (a ...) formals . body)
(plambda: (a ... b ooo) formals . body)]]{
A polymorphic function, abstracted over the type variables A polymorphic function, abstracted over the type variables
@racket[a]. The type variables @racket[a] are bound in both the types @racket[a]. The type variables @racket[a] are bound in both the types
of the formal, and in any type expressions in the @racket[body].} of the formal, and in any type expressions in the @racket[body].}
@ -124,14 +125,16 @@ different arity.
(map + lst1 lst2)]))] (map + lst1 lst2)]))]
For the type declaration of @racket[add-map] look at @racket[case-lambda].} For the type declaration of @racket[add-map] look at @racket[case-lambda].}
@defform[(pcase-lambda: (a ...) [formals body] ...)]{ @defform*[[(pcase-lambda: (a ...) [formals body] ...)
(pcase-lambda: (a ... b ooo) [formals body] ...)]]{
A polymorphic function of multiple arities.} A polymorphic function of multiple arities.}
@defform/subs[(opt-lambda: formals . body) @defform/subs[(opt-lambda: formals . body)
([formals ([v : t] ... [v : t default] ...) ([formals ([v : t] ... [v : t default] ...)
([v : t] ... [v : t default] ... . [v : t *]) ([v : t] ... [v : t default] ... v : t *)
([v : t] ... [v : t default] ... . [v : t ...])])]{ ([v : t] ... [v : t default] ... v : t ooo bound)])]{
A function with optional arguments.} A function with optional arguments.}
@defform[(popt-lambda: (a ...) formals . body)]{ @defform*[[(popt-lambda: (a ...) formals . body)
(popt-lambda: (a ... a ooo) formals . body)]]{
A polymorphic function with optional arguments.} A polymorphic function with optional arguments.}
@ -228,27 +231,31 @@ annotations are optional.
@section{Definitions} @section{Definitions}
@defform*[[(define: v : t e) @defform*[[(define: v : t e)
(define: (f . formals) : t . body)
(define: (a ...) v : t e) (define: (a ...) v : t e)
(define: (a ...) (f . formals) : t . body)]]{ (define: (a ... a ooo) v : t e)
(define: (f . formals) : t . body)
(define: (a ...) (f . formals) : t . body)
(define: (a ... a ooo) (f . formals) : t . body)]]{
These forms define variables, with annotated types. The first form These forms define variables, with annotated types. The first form
defines @racket[v] with type @racket[t] and value @racket[e]. The third defines @racket[v] with type @racket[t] and value @racket[e]. The second
form does the same, but allows the specification of type variables. form does the same, but allows the specification of type variables. The third
The second and fourth forms defines a function @racket[f] with appropriate allows for polydotted variables. The fourth, fifth, and sixth forms define a
types. In most cases, use of @racket[:] is preferred to use of @racket[define:]. function @racket[f] with appropriate types. In most cases, use of @racket[:] is
preferred to use of @racket[define:].
@ex[(define: foo : Integer 10) @ex[(define: foo : Integer 10)
(define: (A) mt-seq : (Sequenceof A) empty-sequence)
(define: (add [first : Integer] (define: (add [first : Integer]
[rest : Integer]) : Integer [rest : Integer]) : Integer
(+ first rest)) (+ first rest))
(define: (A) mt-seq : (Sequenceof A) empty-sequence)
(define: (A) (poly-app [func : (A A -> A)] (define: (A) (poly-app [func : (A A -> A)]
[first : A] [first : A]
[rest : A]) : A [rest : A]) : A
(func first rest))]} (func first rest))]
}
@ -344,19 +351,28 @@ returned by @racket[e], protected by a contract ensuring that it has type
] ]
} }
@defform[(inst e t ...)]{Instantiate the type of @racket[e] with types @defform*[[(inst e t ...)
@racket[t ...]. @racket[e] must have a polymorphic type with the (inst e t ... t ooo bound)]]{
appropriate number of type variables. This is legal only in expression Instantiate the type of @racket[e] with types @racket[t ...] or with the
contexts. poly-dotted types @racket[t ... t ooo bound]. @racket[e] must
have a polymorphic type that can be applied to the supplied number of type
variables. This is legal only in expression contexts.
@ex[(foldl (inst cons Integer Integer) null (list 1 2 3 4)) @ex[(foldl (inst cons Integer Integer) null (list 1 2 3 4))
(: fold-list : (All (A) (Listof A) -> (Listof A))) (: fold-list : (All (A) (Listof A) -> (Listof A)))
(define (fold-list lst) (define (fold-list lst)
(foldl (inst cons A A) null lst)) (foldl (inst cons A A) null lst))
(fold-list (list "1" "2" "3" "4"))]} (fold-list (list "1" "2" "3" "4"))
@defform/none[#{e |@| t ...}]{A reader abbreviation for @racket[(inst e t ...)].} (: my-values : (All (A B ...) (A B ... -> (values A B ... B))))
(define (my-values arg . args)
(apply (inst values A B ... B) arg args))]}
@defform/none[#{e |@| t ...}]{
A reader abbreviation for @racket[(inst e t ...)].}
@defform/none[#{e |@| t ... t ooo bound}]{
A reader abbreviation for @racket[(inst e t ... t ooo bound)].}
@section{Require} @section{Require}

View File

@ -419,17 +419,18 @@ functions and continuation mark functions.
@defform*/subs[#:id -> #:literals (* ...) @defform*/subs[#:id -> #:literals (* ...)
[(dom ... -> rng) [(dom ... -> rng)
(dom ... rest * -> rng) (dom ... rest * -> rng)
(dom ... rest #,(racket ...) bound -> rng) (dom ... rest ooo bound -> rng)
(dom -> rng : pred)] (dom -> rng : pred)]
([dom type ([ooo #,(racket ...)]
[dom type
(code:line keyword type) (code:line keyword type)
[keyword type]])]{ [keyword type]])]{
is the type of functions from the (possibly-empty) The type of functions from the (possibly-empty)
sequence @racket[dom ...] to the @racket[rng] type. The second form sequence @racket[dom ...] to the @racket[rng] type. The second form
specifies a uniform rest argument of type @racket[rest], and the specifies a uniform rest argument of type @racket[rest], and the
third form specifies a non-uniform rest argument of type third form specifies a non-uniform rest argument of type
@racket[rest] with bound @racket[bound]. In the third form, the @racket[rest] with bound @racket[bound]. In the third form, the
second occurrence of @racket[...] is literal, and @racket[bound] @racket[...] introduced by @racket[ooo] is literal, and @racket[bound]
must be an identifier denoting a type variable. In the fourth form, must be an identifier denoting a type variable. In the fourth form,
there must be only one @racket[dom] and @racket[pred] is the type there must be only one @racket[dom] and @racket[pred] is the type
checked by the predicate. @racket[dom] can include both mandatory and checked by the predicate. @racket[dom] can include both mandatory and
@ -461,7 +462,9 @@ functions and continuation mark functions.
@defform/none[(t t1 t2 ...)]{is the instantiation of the parametric type @defform/none[(t t1 t2 ...)]{is the instantiation of the parametric type
@racket[t] at types @racket[t1 t2 ...]} @racket[t] at types @racket[t1 t2 ...]}
@defform[(All (v ...) t)]{is a parameterization of type @racket[t], with @defform*[[(All (a ...) t)
(All (a ... a ooo) t)]]{
is a parameterization of type @racket[t], with
type variables @racket[v ...]. If @racket[t] is a function type type variables @racket[v ...]. If @racket[t] is a function type
constructed with @racket[->], the outer pair of parentheses constructed with @racket[->], the outer pair of parentheses
around the function type may be omitted. around the function type may be omitted.