From b207bb9c0f615fa3b8bb68f07c6a941b348eba68 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Wed, 10 Mar 2010 00:17:33 +0000 Subject: [PATCH] update docs to use `define-type' document `define-predicate' svn: r18498 original commit: 24b9078560d936d046fe14b3198432a3f64cbd1c --- collects/typed-scheme/scribblings/begin.scrbl | 4 ++-- collects/typed-scheme/scribblings/more.scrbl | 6 +++--- .../typed-scheme/scribblings/ts-guide.scrbl | 12 ++++++------ .../scribblings/ts-reference.scrbl | 18 ++++++++++++------ collects/typed-scheme/scribblings/types.scrbl | 8 ++++---- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/collects/typed-scheme/scribblings/begin.scrbl b/collects/typed-scheme/scribblings/begin.scrbl index 7bc686a5..61a32344 100644 --- a/collects/typed-scheme/scribblings/begin.scrbl +++ b/collects/typed-scheme/scribblings/begin.scrbl @@ -70,7 +70,7 @@ represent these using @italic{union types}, written @scheme[(U t1 t2 ...)]. @schememod[ typed/scheme -(define-type-alias Tree (U leaf node)) +(define-type Tree (U leaf node)) (define-struct: leaf ([val : Number])) (define-struct: node ([left : Tree] [right : Tree])) @@ -88,7 +88,7 @@ typed/scheme ] In this module, we have defined two new datatypes: @scheme[leaf] and -@scheme[node]. We've also defined the type alias @scheme[Tree] to be +@scheme[node]. We've also defined the type name @scheme[Tree] to be @scheme[(U node leaf)], which represents a binary tree of numbers. In essence, we are saying that the @scheme[tree-height] function accepts a @scheme[Tree], which is either a @scheme[node] or a @scheme[leaf], diff --git a/collects/typed-scheme/scribblings/more.scrbl b/collects/typed-scheme/scribblings/more.scrbl index 998148c6..77eebf1c 100644 --- a/collects/typed-scheme/scribblings/more.scrbl +++ b/collects/typed-scheme/scribblings/more.scrbl @@ -152,9 +152,9 @@ variable has type @scheme[(Integer (Listof Integer) -> Integer)]. @section{New Type Names} -Any type can be given a name with @scheme[define-type-alias]. +Any type can be given a name with @scheme[define-type]. -@schemeblock[(define-type-alias NN (Number -> Number))] +@schemeblock[(define-type NN (Number -> Number))] Anywhere the name @scheme[NN] is used, it is expanded to -@scheme[(Number -> Number)]. Type aliases may not be recursive. \ No newline at end of file +@scheme[(Number -> Number)]. Type names may not be recursive. \ No newline at end of file diff --git a/collects/typed-scheme/scribblings/ts-guide.scrbl b/collects/typed-scheme/scribblings/ts-guide.scrbl index 1c160a26..0d69e20c 100644 --- a/collects/typed-scheme/scribblings/ts-guide.scrbl +++ b/collects/typed-scheme/scribblings/ts-guide.scrbl @@ -141,7 +141,7 @@ represent these using @italic{union types}, written @scheme[(U t1 t2 ...)]. @schememod[ typed-scheme -(define-type-alias Tree (U leaf node)) +(define-type Tree (U leaf node)) (define-struct: leaf ([val : Number])) (define-struct: node ([left : Tree] [right : Tree])) @@ -159,7 +159,7 @@ typed-scheme ] In this module, we have defined two new datatypes: @scheme[leaf] and -@scheme[node]. We've also defined the type alias @scheme[Tree] to be +@scheme[node]. We've also defined the type name @scheme[Tree] to be @scheme[(U node leaf)], which represents a binary tree of numbers. In essence, we are saying that the @scheme[tree-height] function accepts a @scheme[Tree], which is either a @scheme[node] or a @scheme[leaf], @@ -217,7 +217,7 @@ typed-scheme (define-struct: Nothing ()) (define-struct: (a) Just ([v : a])) -(define-type-alias (Maybe a) (U Nothing (Just a))) +(define-type (Maybe a) (U Nothing (Just a))) (: find (Number (Listof Number) -> (Maybe Number))) (define (find v l) @@ -241,11 +241,11 @@ one element, whose type is that of the type argument to this case) are written before the type name, and can be referred to in the types of the fields. -The type alias definiton +The type definiton @schemeblock[ - (define-type-alias (Maybe a) (U Nothing (Just a))) + (define-type (Maybe a) (U Nothing (Just a))) ] -creates a parameterized alias --- @scheme[Maybe] is a potential +creates a parameterized type --- @scheme[Maybe] is a potential container for whatever type is supplied. The @scheme[find] function takes a number @scheme[v] and list, and diff --git a/collects/typed-scheme/scribblings/ts-reference.scrbl b/collects/typed-scheme/scribblings/ts-reference.scrbl index f500ee1b..ae7d5b31 100644 --- a/collects/typed-scheme/scribblings/ts-reference.scrbl +++ b/collects/typed-scheme/scribblings/ts-reference.scrbl @@ -206,14 +206,20 @@ structure is a substructure of @scheme[parent]. When Like @scheme[define-struct:], but defines an procedural structure. The procdure @scheme[e] is used as the value for @scheme[prop:procedure], and must have type @scheme[proc-t].} -@subsection{Type Aliases} -@defform*[[(define-type-alias name t) - (define-type-alias (name v ...) t)]]{ +@subsection{Names for Types} +@defform*[[(define-type name t) + (define-type (name v ...) t)]]{ The first form defines @scheme[name] as type, with the same meaning as @scheme[t]. The second form is equivalent to -@scheme[(define-type-alias name (All (v ...) t))]. Type aliases may -refer to other type aliases or types defined in the same module, but -cycles among type aliases are prohibited.} +@scheme[(define-type name (All (v ...) t))]. Type names may +refer to other types defined in the same module, but +cycles among them are prohibited.} + +@subsection{Generating Predicates Automatically} +@defform[(define-predicate name t)]{ +Defines @scheme[name] as a predicate for the type @scheme[t]. +@scheme[name] has the type @scheme[(Any -> Boolean : t)]. +@scheme[t] may not contain function types.} @subsection{Type Annotation and Instantiation} diff --git a/collects/typed-scheme/scribblings/types.scrbl b/collects/typed-scheme/scribblings/types.scrbl index bb22b878..24005507 100644 --- a/collects/typed-scheme/scribblings/types.scrbl +++ b/collects/typed-scheme/scribblings/types.scrbl @@ -175,7 +175,7 @@ typed/scheme (define-struct: None ()) (define-struct: (a) Some ([v : a])) -(define-type-alias (Opt a) (U None (Some a))) +(define-type (Opt a) (U None (Some a))) (: find (Number (Listof Number) -> (Opt Number))) (define (find v l) @@ -199,11 +199,11 @@ one element, whose type is that of the type argument to this case) are written before the type name, and can be referred to in the types of the fields. -The type alias definiton +The type definiton @schemeblock[ - (define-type-alias (Opt a) (U None (Some a))) + (define-type (Opt a) (U None (Some a))) ] -creates a parameterized alias --- @scheme[Opt] is a potential +creates a parameterized type --- @scheme[Opt] is a potential container for whatever type is supplied. The @scheme[find] function takes a number @scheme[v] and list, and