On this page:
8.18
top
up

1Quick StartπŸ”— i

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:

(struct pt(xy))
; distance: ptpt-> real
(define (distancep1p2)
(sqrt (+ (sqr (- (pt-xp2)(pt-xp1)))
(sqr (- (pt-yp2)(pt-yp1))))))

Here is the same program, in typed/racket:

(struct pt([x: Real ][y: Real ]))
(: distance(-> ptptReal ))
(define (distancep1p2)
(sqrt (+ (sqr (- (pt-xp2)(pt-xp1)))
(sqr (- (pt-yp2)(pt-yp1))))))

1.1Using Typed Racket from the Racket REPLπŸ”— i

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

top
up

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /