Fix docs to work around schememod bug

svn: r11342
This commit is contained in:
Sam Tobin-Hochstadt 2008-08-19 19:57:59 +00:00
parent d546d6e045
commit a16f879e24

View File

@ -41,7 +41,8 @@ easy to start using Typed Scheme.
The following program defines the Fibonacci function in PLT Scheme: The following program defines the Fibonacci function in PLT Scheme:
@schememod[scheme @schememod[
scheme
(define (fib n) (define (fib n)
(cond [(= 0 n) 1] (cond [(= 0 n) 1]
[(= 1 n) 1] [(= 1 n) 1]
@ -50,7 +51,8 @@ The following program defines the Fibonacci function in PLT Scheme:
This program defines the same program using Typed Scheme. This program defines the same program using Typed Scheme.
@schememod[typed-scheme @schememod[
typed-scheme
(: fib (Number -> Number)) (: fib (Number -> Number))
(define (fib n) (define (fib n)
(cond [(= 0 n) 1] (cond [(= 0 n) 1]
@ -76,7 +78,8 @@ PLT Scheme program to transform it into a Typed Scheme program.
Other typed binding forms are also available. For example, we could have Other typed binding forms are also available. For example, we could have
rewritten our fibonacci program as follows: rewritten our fibonacci program as follows:
@schememod[typed-scheme @schememod[
typed-scheme
(: fib (Number -> Number)) (: fib (Number -> Number))
(define (fib n) (define (fib n)
(let ([base? (or (= 0 n) (= 1 n))]) (let ([base? (or (= 0 n) (= 1 n))])
@ -91,7 +94,8 @@ annotations are required. Typed Scheme infers the type of
We can also define mutually-recursive functions: We can also define mutually-recursive functions:
@schememod[typed-scheme @schememod[
typed-scheme
(: my-odd? (Number -> Boolean)) (: my-odd? (Number -> Boolean))
(define (my-odd? n) (define (my-odd? n)
(if (= 0 n) #f (if (= 0 n) #f
@ -116,7 +120,8 @@ to PLT Scheme structures. The following program defines a date
structure and a function that formats a date as a string, using PLT structure and a function that formats a date as a string, using PLT
Scheme's built-in @scheme[format] function. Scheme's built-in @scheme[format] function.
@schememod[typed-scheme @schememod[
typed-scheme
(define-struct: Date ([day : Number] [month : String] [year : Number])) (define-struct: Date ([day : Number] [month : String] [year : Number]))
(: format-date (Date -> String)) (: format-date (Date -> String))
@ -141,7 +146,8 @@ we would have with @scheme[define-struct].
Many data structures involve multiple variants. In Typed Scheme, we Many data structures involve multiple variants. In Typed Scheme, we
represent these using @italic{union types}, written @scheme[(U t1 t2 ...)]. represent these using @italic{union types}, written @scheme[(U t1 t2 ...)].
@schememod[typed-scheme @schememod[
typed-scheme
(define-type-alias Tree (U leaf node)) (define-type-alias Tree (U leaf node))
(define-struct: leaf ([val : Number])) (define-struct: leaf ([val : Number]))
(define-struct: node ([left : Tree] [right : Tree])) (define-struct: node ([left : Tree] [right : Tree]))
@ -195,7 +201,8 @@ Virtually every Scheme program uses lists and sexpressions. Fortunately, Typed
Scheme can handle these as well. A simple list processing program can be Scheme can handle these as well. A simple list processing program can be
written like this: written like this:
@schememod[typed-scheme @schememod[
typed-scheme
(: sum-list ((Listof Number) -> Number)) (: sum-list ((Listof Number) -> Number))
(define (sum-list l) (define (sum-list l)
(cond [(null? l) 0] (cond [(null? l) 0]
@ -212,7 +219,8 @@ want.
We can define our own type constructors as well. For example, here is We can define our own type constructors as well. For example, here is
an analog of the @tt{Maybe} type constructor from Haskell: an analog of the @tt{Maybe} type constructor from Haskell:
@schememod[typed-scheme @schememod[
typed-scheme
(define-struct: Nothing ()) (define-struct: Nothing ())
(define-struct: (a) Just ([v : a])) (define-struct: (a) Just ([v : a]))
@ -258,7 +266,8 @@ Sometimes functions over polymorphic data structures only concern
themselves with the form of the structure. For example, one might themselves with the form of the structure. For example, one might
write a function that takes the length of a list of numbers: write a function that takes the length of a list of numbers:
@schememod[typed-scheme @schememod[
typed-scheme
(: list-number-length ((Listof Number) -> Integer)) (: list-number-length ((Listof Number) -> Integer))
(define (list-number-length l) (define (list-number-length l)
(if (null? l) (if (null? l)
@ -267,7 +276,8 @@ write a function that takes the length of a list of numbers:
and also a function that takes the length of a list of strings: and also a function that takes the length of a list of strings:
@schememod[typed-scheme @schememod[
typed-scheme
(: list-string-length ((Listof String) -> Integer)) (: list-string-length ((Listof String) -> Integer))
(define (list-string-length l) (define (list-string-length l)
(if (null? l) (if (null? l)
@ -281,7 +291,8 @@ definition.
We can abstract over the type of the element as follows: We can abstract over the type of the element as follows:
@schememod[typed-scheme @schememod[
typed-scheme
(: list-length (All (A) ((Listof A) -> Integer))) (: list-length (All (A) ((Listof A) -> Integer)))
(define (list-length l) (define (list-length l)
(if (null? l) (if (null? l)
@ -301,7 +312,8 @@ Typed Scheme can handle some uses of rest arguments.
In Scheme, one can write a function that takes an arbitrary In Scheme, one can write a function that takes an arbitrary
number of arguments as follows: number of arguments as follows:
@schememod[scheme @schememod[
scheme
(define (sum . xs) (define (sum . xs)
(if (null? xs) (if (null? xs)
0 0
@ -318,7 +330,8 @@ to the rest parameter. So the examples above evaluate to
We can define such functions in Typed Scheme as well: We can define such functions in Typed Scheme as well:
@schememod[typed-scheme @schememod[
typed-scheme
(: sum (Number * -> Number)) (: sum (Number * -> Number))
(define (sum . xs) (define (sum . xs)
(if (null? xs) (if (null? xs)
@ -333,7 +346,8 @@ of the rest parameter is used at the same type.
However, the rest argument may be used as a heterogeneous list. However, the rest argument may be used as a heterogeneous list.
Take this (simplified) definition of the Scheme function @scheme[map]: Take this (simplified) definition of the Scheme function @scheme[map]:
@schememod[scheme @schememod[
scheme
(define (map f as . bss) (define (map f as . bss)
(if (or (null? as) (if (or (null? as)
(ormap null? bss)) (ormap null? bss))
@ -358,7 +372,8 @@ The example uses of @scheme[map] evaluate to @schemeresult[(list 2 3 4 5)],
In Typed Scheme, we can define @scheme[map] as follows: In Typed Scheme, we can define @scheme[map] as follows:
@schememod[typed-scheme @schememod[
typed-scheme
(: map (: map
(All (C A B ...) (All (C A B ...)
((A B ... B -> C) (Listof A) (Listof B) ... B ((A B ... B -> C) (Listof A) (Listof B) ... B