Adding documentation for cast and make-predicate.

Also converted tabs to spaces.
This commit is contained in:
Eric Dobson 2012-08-20 22:20:58 -07:00 committed by Sam Tobin-Hochstadt
parent 3c744229e8
commit 1248b32e73

View File

@ -43,9 +43,9 @@ creating new types, and annotating expressions.
Local bindings, like @racket[let], each with Local bindings, like @racket[let], each with
associated types. In the second form, @racket[_t0] is the type of the associated types. In the second form, @racket[_t0] is the type of the
result of @racket[_loop] (and thus the result of the entire result of @racket[_loop] (and thus the result of the entire
expression as well as the final expression as well as the final
expression in @racket[body]). expression in @racket[body]).
Type annotations are optional. Type annotations are optional.
@ex[(: filter-even : (Listof Natural) (Listof Natural) -> (Listof Natural)) @ex[(: filter-even : (Listof Natural) (Listof Natural) -> (Listof Natural))
(define (filter-even lst accum) (define (filter-even lst accum)
(if (null? lst) (if (null? lst)
@ -88,8 +88,8 @@ 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 ...])])]{
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)].}
@ -116,7 +116,7 @@ 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 ...])])]{
A function with optional arguments.} A function with optional arguments.}
@defform[(popt-lambda: (a ...) formals . body)]{ @defform[(popt-lambda: (a ...) formals . body)]{
A polymorphic function with optional arguments.} A polymorphic function with optional arguments.}
@ -128,9 +128,9 @@ A polymorphic function with optional arguments.}
expr ...+) expr ...+)
([type-ann-maybe code:blank ([type-ann-maybe code:blank
@code:line[: u]] @code:line[: u]]
[for:-clause [id : t seq-expr] [for:-clause [id : t seq-expr]
[id seq-expr] [id seq-expr]
@code:line[#:when guard]])]{ @code:line[#:when guard]])]{
Like @racket[for], but each @racket[id] having the associated type Like @racket[for], but each @racket[id] having the associated type
@racket[t]. Since the return type is always @racket[Void], annotating @racket[t]. Since the return type is always @racket[Void], annotating
the return type of a @racket[for] form is optional. Unlike the return type of a @racket[for] form is optional. Unlike
@ -175,10 +175,10 @@ annotated with a @racket[Listof] type. All annotations are optional.
@deftogether[[ @deftogether[[
@defform[(for/lists: type-ann-maybe ([id : t] ...) @defform[(for/lists: type-ann-maybe ([id : t] ...)
(for:-clause ...) (for:-clause ...)
expr ...+)] expr ...+)]
@defform[(for/fold: type-ann-maybe ([id : t init-expr] ...) @defform[(for/fold: type-ann-maybe ([id : t init-expr] ...)
(for:-clause ...) (for:-clause ...)
expr ...+)]]]{ expr ...+)]]]{
These behave like their non-annotated counterparts. Unlike the above, These behave like their non-annotated counterparts. Unlike the above,
@racket[#:when] clauses can be used freely with these. @racket[#:when] clauses can be used freely with these.
} }
@ -188,10 +188,10 @@ These behave like their non-annotated counterparts. Unlike the above,
expr ...+)] expr ...+)]
@defform[(for*/lists: type-ann-maybe ([id : t] ...) @defform[(for*/lists: type-ann-maybe ([id : t] ...)
(for:-clause ...) (for:-clause ...)
expr ...+)] expr ...+)]
@defform[(for*/fold: type-ann-maybe ([id : t init-expr] ...) @defform[(for*/fold: type-ann-maybe ([id : t init-expr] ...)
(for:-clause ...) (for:-clause ...)
expr ...+)]]]{ expr ...+)]]]{
These behave like their non-annotated counterparts. These behave like their non-annotated counterparts.
} }
@ -215,8 +215,8 @@ annotations are optional.
@section{Definitions} @section{Definitions}
@defform*[[(define: v : t e) @defform*[[(define: v : t e)
(define: (f . formals) : t . body) (define: (f . formals) : t . body)
(define: (a ...) (f . formals) : t . body)]]{ (define: (a ...) (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 defines @racket[v] with type @racket[t] and value @racket[e]. The
second and third forms defines a function @racket[f] with appropriate second and third forms defines a function @racket[f] with appropriate
@ -266,7 +266,7 @@ corresponding to @racket[define-struct].}
@section{Names for Types} @section{Names for Types}
@defform*[[(define-type name t) @defform*[[(define-type name t)
(define-type (name v ...) t)]]{ (define-type (name v ...) t)]]{
The first form defines @racket[name] as type, with the same meaning as The first form defines @racket[name] as type, with the same meaning as
@racket[t]. The second form is equivalent to @racket[t]. The second form is equivalent to
@racket[(define-type name (All (v ...) t))]. Type names may @racket[(define-type name (All (v ...) t))]. Type names may
@ -277,11 +277,13 @@ cycles among them are prohibited.
(define-type (ListofPairs A) (Listof (Pair A A)))]} (define-type (ListofPairs A) (Listof (Pair A A)))]}
@section{Generating Predicates Automatically} @section{Generating Predicates Automatically}
@defform[(define-predicate name t)]{
Defines @racket[name] as a predicate for the type @racket[t].
@racket[name] has the type @racket[(Any -> Boolean : t)].
@racket[t] may not contain function types.}
@defform[(make-predicate t)]{
Evaluates to a predicate for the type @racket[t], with the type
@racket[(Any -> Boolean : t)]. @racket[t] may not contain function types.}
@defform[(define-predicate name t)]{
Equivalent to @racket[(define name (make-predicate t))].
@section{Type Annotation and Instantiation} @section{Type Annotation and Instantiation}
@ -303,6 +305,11 @@ This is legal only in expression contexts.}
@defform/none[#{e :: t}]{A reader abbreviation for @racket[(ann e t)].} @defform/none[#{e :: t}]{A reader abbreviation for @racket[(ann e t)].}
@defform[(cast e t)]{The entire expression has the type @racket[t], while
@racket[e] may have any type. The value of the entire expression is the value
returned by @racket[e], protected by a contract ensuring that it has type
@racket[t]. This is legal only in expression contexts.}
@defform[(inst e t ...)]{Instantiate the type of @racket[e] with types @defform[(inst e t ...)]{Instantiate the type of @racket[e] with types
@racket[t ...]. @racket[e] must have a polymorphic type with the @racket[t ...]. @racket[e] must have a polymorphic type with the
appropriate number of type variables. This is legal only in expression appropriate number of type variables. This is legal only in expression
@ -325,11 +332,11 @@ naming a predicate, and @racket[_r] is an optionally-renamed identifier.
@defform/subs[#:literals (struct opaque) @defform/subs[#:literals (struct opaque)
(require/typed m rt-clause ...) (require/typed m rt-clause ...)
([rt-clause [r t] ([rt-clause [r t]
[struct name ([f : t] ...) [struct name ([f : t] ...)
struct-option ...] struct-option ...]
[struct (name parent) ([f : t] ...) [struct (name parent) ([f : t] ...)
struct-option ...] struct-option ...]
[opaque t pred]] [opaque t pred]]
[struct-option [struct-option
(code:line #:constructor-name constructor-id) (code:line #:constructor-name constructor-id)
(code:line #:extra-constructor-name constructor-id)])] (code:line #:extra-constructor-name constructor-id)])]