Special Form Reference
Typed Scheme provides a variety of special forms above and beyond those in PLT Scheme. They are used for annotating variables with types, creating new types, and annotating expressions.
4.1 Binding Forms
loop, f, a, and v are names, t is a type.
e and body are expressions.
(define: (f [v : t] ...) : t body)(define: v : t e)(pdefine: (a ...) (f [v : t] ...) : t body)(let: ([v : t e] ...) body)(let: loop : t0 ([v : t e] ...) body)wheret0is the type of the result ofloop(and thus the result of the entire expression).(letrec: ([v : t e] ...) body(let*: ([v : t e] ...) body)(lambda: ([v : t] ...) body)(lambda: ([v : t] ... . [v : t]) body)(plambda: (a ...) ([v : t] ...) body)(plambda: (a ...) ([v : t] ... . [v : t]) body)(case-lambda: [formals body] ...)whereformalsis like the second element of alambda:(pcase-lambda: (a ...) [formals body] ...)whereformalsis like the third element of aplambda:
4.2 Structure Defintions
name, parent, f, and v are names,
t is a type. parent must name a structure type.
(define-typed-struct name ([f : t] ...))(define-typed-struct (name parent) ([f : t] ...))(define-typed-struct (v ...) name ([f : t] ...))(define-typed-struct (v ...) (name parent) ([f : t] ...))
4.3 Type Aliases
name and v are names, t is a type.
(define-type-alias name t)(define-type-alias (name v ...) t)
4.4 Type Annotation
v is a variable name, e is an expression, t is a type.
These annotations require the use of the following declaration before the beginning of the module:
#reader (planet "typed-reader.ss" ("plt" "typed-scheme.plt"))
This will not affect the reading or parsing of any other syntax.
#{v : t}This is legal only for binding occurences ofv#{e :: t}This is legal only in expression contexts
4.5 Require
v is a variable name, t is a type, and m is
a require-spec.
(require/typed v t m)