On this page:
1.1 Using Typed Racket from the Racket REPL
8.15

1 Quick Start🔗ℹ

Given a module written in the racket language, using Typed Racket requires the following steps:

  1. Change the language to typed/racket.

  2. Change the uses of (require mod) to (require typed/mod).

  3. Annotate structure definitions and top-level definitions with their types.

Then, when the program is run, it will automatically be typechecked before any execution, and any type errors will be reported. If there are any type errors, the program will not run.

Here is an example program, written in the racket language:

#lang racket
(struct pt (x y))
 
; distance : pt pt -> real
(define (distance p1 p2)
  (sqrt (+ (sqr (- (pt-x p2) (pt-x p1)))
           (sqr (- (pt-y p2) (pt-y p1))))))

Here is the same program, in typed/racket:

#lang typed/racket
(struct pt ([x : Real] [y : Real]))
 
(: distance (-> pt pt Real))
(define (distance p1 p2)
  (sqrt (+ (sqr (- (pt-x p2) (pt-x p1)))
           (sqr (- (pt-y p2) (pt-y p1))))))

1.1 Using Typed Racket from the Racket REPL🔗ℹ

It is possible to use Typed Racket from the Racket REPL. To do so, start Racket with the following command line:
  racket -I typed/racket