Given a module written in the racket language, using Typed Racket requires the following steps:
Change the language to typed/racket.
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))))))