On this page:
The Typed Racket Guide
8.15.0.7

The Typed Racket Guide🔗ℹ

Sam Tobin-Hochstadt <samth@racket-lang.org>,
Vincent St-Amour <stamourv@racket-lang.org>,
Eric Dobson <endobson@racket-lang.org>,
and Asumu Takikawa <asumu@racket-lang.org>

Typed Racket is Racket’s gradually-typed sister language which allows the incremental addition of statically-checked type annotations. This guide is intended for programmers familiar with Racket. For an introduction to Racket, see The Racket Guide.

For the precise details, also see The Typed Racket Reference.

    1 Quick Start

      1.1 Using Typed Racket from the Racket REPL

    2 Beginning Typed Racket

      2.1 Datatypes and Unions

      2.2 Type Errors

    3 Specifying Types

      3.1 Type Annotation and Binding Forms

        3.1.1 Annotating Definitions

        3.1.2 Annotating Local Binding

        3.1.3 Annotating Functions

        3.1.4 Annotating Single Variables

        3.1.5 Annotating Expressions

      3.2 Type Inference

        3.2.1 When do you need type annotations?

      3.3 New Type Names

    4 Types in Typed Racket

      4.1 Basic Types

      4.2 Function Types

      4.3 Types for Functions with Optional or Keyword Arguments

      4.4 Union Types

      4.5 Recursive Types

      4.6 Structure Types

      4.7 Types for Structure Type Properties

      4.8 Subtyping

      4.9 Polymorphism

        4.9.1 Type Constructors

        4.9.2 Polymorphic Data Structures

        4.9.3 Polymorphic Functions

        4.9.4 Lexically Scoped Type Variables

      4.10 Variable-Arity Functions: Programming with Rest Arguments

        4.10.1 Uniform Variable-Arity Functions

        4.10.2 Non-Uniform Variable-Arity Functions

    5 Occurrence Typing

      5.1 Basic Occurrence Typing

      5.2 Propositions and Predicates

        5.2.1 Specifying Propositions

        5.2.2 One-sided Propositions

      5.3 Other conditionals and assertions

      5.4 A caveat about set!

      5.5 Access to structure fields

      5.6 let-aliasing

    6 Typed-Untyped Interaction

      6.1 Using Untyped Code in Typed Code

        6.1.1 Opaque Types

      6.2 Using Typed Code in Untyped Code

      6.3 Protecting Typed-Untyped Interaction

        6.3.1 Deep Types: Completely Reliable

        6.3.2 Shallow Types: Sound Types, Low-Cost Interactions

        6.3.3 Optional Types: It’s Just Racket

        6.3.4 When to Use Deep, Shallow, or Optional?

    7 Optimization in Typed Racket

      7.1 Turning the optimizer off

      7.2 Getting the most out of the optimizer

        7.2.1 Numeric types

        7.2.2 Lists

        7.2.3 Vectors

        7.2.4 Contract boundaries

    8 Caveats and Limitations

      8.1 The Integer type and integer?

      8.2 Type inference for polymorphic functions

      8.3 Typed-untyped interaction and contract generation

      8.4 Unsupported features

      8.5 Type generalization

      8.6 Macros and compile-time computation

      8.7 Expensive contract boundaries

      8.8 Pattern Matching and Occurrence Typing

      8.9 is-a? and Occurrence Typing