Many of the most common languages in use today require you to specify the types on inputs and outputs of a function. That is to say, they every function requires a signature.
There are two main benefits to this kind of typing:
Speed. The code runs faster when the computer has no doubt that a certain variable always contains a certain kind of value, like a posn.
Reliability. The computer can check before starting the program
that there is never a time when the posn-x
function is called on
a color
. In regular Racket, this kind of mistake causes the
program to halt with an error when the mistake runs. In Typed
Racket, the mistake is detected before the program starts running -
there is no suspense and no uncertainty.
One time per computer:
File -> “Install Package…” -> Enter “2htdp-typed” and choose the “Install” button.
Beginning of every file:
#lang typed/racket
(require typed/lang/posn)
(require typed/2htdp/image)
(require typed/2htdp/universe)
(require typed/test-engine/racket-tests)
End of the file - you need to run the check-expects manually.
(test)