define-struct:' ->
struct:' in docs.
Fix typo.
This commit is contained in:
parent
431ff8d794
commit
1ce4040cd2
|
@ -23,7 +23,7 @@ are provided as well; for example, the
|
||||||
@racketmodname[typed/racket/base] language corresponds to
|
@racketmodname[typed/racket/base] language corresponds to
|
||||||
@racketmodname[racket/base].
|
@racketmodname[racket/base].
|
||||||
|
|
||||||
@racketblock[(define-struct: pt ([x : Real] [y : Real]))]
|
@racketblock[(struct: pt ([x : Real] [y : Real]))]
|
||||||
|
|
||||||
@margin-note{Many forms in Typed Racket have the same name as the
|
@margin-note{Many forms in Typed Racket have the same name as the
|
||||||
untyped forms, with a @racket[:] suffix.}
|
untyped forms, with a @racket[:] suffix.}
|
||||||
|
@ -31,10 +31,10 @@ This defines a new structure, name @racket[pt], with two fields,
|
||||||
@racket[x] and @racket[y]. Both fields are specified to have the type
|
@racket[x] and @racket[y]. Both fields are specified to have the type
|
||||||
@racket[Real], which corresponds to the @rtech{real numbers}.
|
@racket[Real], which corresponds to the @rtech{real numbers}.
|
||||||
The
|
The
|
||||||
@racket[define-struct:] form corresponds to the @racket[define-struct]
|
@racket[struct:] form corresponds to the @racket[struct]
|
||||||
form from @racketmodname[racket]---when porting a program from
|
form from @racketmodname[racket]---when porting a program from
|
||||||
@racketmodname[racket] to @racketmodname[typed/racket], uses of
|
@racketmodname[racket] to @racketmodname[typed/racket], uses of
|
||||||
@racket[define-struct] should be changed to @racket[define-struct:].
|
@racket[struct] should be changed to @racket[struct:].
|
||||||
|
|
||||||
@racketblock[(: mag (pt -> Number))]
|
@racketblock[(: mag (pt -> Number))]
|
||||||
|
|
||||||
|
@ -71,8 +71,8 @@ represent these using @italic{union types}, written @racket[(U t1 t2 ...)].
|
||||||
@racketmod[
|
@racketmod[
|
||||||
typed/racket
|
typed/racket
|
||||||
(define-type Tree (U leaf node))
|
(define-type Tree (U leaf node))
|
||||||
(define-struct: leaf ([val : Number]))
|
(struct: leaf ([val : Number]))
|
||||||
(define-struct: node ([left : Tree] [right : Tree]))
|
(struct: node ([left : Tree] [right : Tree]))
|
||||||
|
|
||||||
(: tree-height (Tree -> Integer))
|
(: tree-height (Tree -> Integer))
|
||||||
(define (tree-height t)
|
(define (tree-height t)
|
||||||
|
|
|
@ -397,7 +397,7 @@ corresponding to @racket[define-struct].}
|
||||||
@defform/subs[
|
@defform/subs[
|
||||||
(define-struct/exec: name-spec ([f : t] ...) [e : proc-t])
|
(define-struct/exec: name-spec ([f : t] ...) [e : proc-t])
|
||||||
([name-spec name (name parent)])]{
|
([name-spec name (name parent)])]{
|
||||||
Like @racket[define-struct:], but defines an procedural structure.
|
Like @racket[define-struct:], but defines a procedural structure.
|
||||||
The procdure @racket[e] is used as the value for @racket[prop:procedure], and must have type @racket[proc-t].}
|
The procdure @racket[e] is used as the value for @racket[prop:procedure], and must have type @racket[proc-t].}
|
||||||
|
|
||||||
@subsection{Names for Types}
|
@subsection{Names for Types}
|
||||||
|
|
|
@ -102,12 +102,12 @@ refers to the whole binary tree type within the body of the
|
||||||
|
|
||||||
@section{Structure Types}
|
@section{Structure Types}
|
||||||
|
|
||||||
Using @racket[define-struct:] introduces new types, distinct from any
|
Using @racket[struct:] introduces new types, distinct from any
|
||||||
previous type.
|
previous type.
|
||||||
|
|
||||||
@racketblock[(define-struct: point ([x : Real] [y : Real]))]
|
@racketblock[(struct: point ([x : Real] [y : Real]))]
|
||||||
|
|
||||||
Instances of this structure, such as @racket[(make-point 7 12)], have type @racket[point].
|
Instances of this structure, such as @racket[(point 7 12)], have type @racket[point].
|
||||||
|
|
||||||
@section{Subtyping}
|
@section{Subtyping}
|
||||||
|
|
||||||
|
@ -172,25 +172,25 @@ an analog of the @tt{Maybe} type constructor from Haskell:
|
||||||
|
|
||||||
@racketmod[
|
@racketmod[
|
||||||
typed/racket
|
typed/racket
|
||||||
(define-struct: None ())
|
(struct: None ())
|
||||||
(define-struct: (a) Some ([v : a]))
|
(struct: (a) Some ([v : a]))
|
||||||
|
|
||||||
(define-type (Opt a) (U None (Some a)))
|
(define-type (Opt a) (U None (Some a)))
|
||||||
|
|
||||||
(: find (Number (Listof Number) -> (Opt Number)))
|
(: find (Number (Listof Number) -> (Opt Number)))
|
||||||
(define (find v l)
|
(define (find v l)
|
||||||
(cond [(null? l) (make-None)]
|
(cond [(null? l) (None)]
|
||||||
[(= v (car l)) (make-Some v)]
|
[(= v (car l)) (Some v)]
|
||||||
[else (find v (cdr l))]))
|
[else (find v (cdr l))]))
|
||||||
]
|
]
|
||||||
|
|
||||||
The first @racket[define-struct:] defines @racket[None] to be
|
The first @racket[struct:] defines @racket[None] to be
|
||||||
a structure with no contents.
|
a structure with no contents.
|
||||||
|
|
||||||
The second definition
|
The second definition
|
||||||
|
|
||||||
@racketblock[
|
@racketblock[
|
||||||
(define-struct: (a) Some ([v : a]))
|
(struct: (a) Some ([v : a]))
|
||||||
]
|
]
|
||||||
|
|
||||||
creates a parameterized type, @racket[Just], which is a structure with
|
creates a parameterized type, @racket[Just], which is a structure with
|
||||||
|
@ -207,8 +207,8 @@ creates a parameterized type --- @racket[Opt] is a potential
|
||||||
container for whatever type is supplied.
|
container for whatever type is supplied.
|
||||||
|
|
||||||
The @racket[find] function takes a number @racket[v] and list, and
|
The @racket[find] function takes a number @racket[v] and list, and
|
||||||
produces @racket[(make-Some v)] when the number is found in the list,
|
produces @racket[(Some v)] when the number is found in the list,
|
||||||
and @racket[(make-None)] otherwise. Therefore, it produces a
|
and @racket[(None)] otherwise. Therefore, it produces a
|
||||||
@racket[(Opt Number)], just as the annotation specified.
|
@racket[(Opt Number)], just as the annotation specified.
|
||||||
|
|
||||||
@subsection{Polymorphic Functions}
|
@subsection{Polymorphic Functions}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user