Danny Yu gave a great answer. I just wanted to expand it and note that Racket gives you more flexibility about where your contract is concluded (for example, where to put the border of the contract). For example, you can use the define/contract form:
-> (define/contract (true? expr) (-> boolean? boolean?) (and (boolean? expr) expr
which will set contract validation between true? and all other code:
-> (true? "foo") ; true?: contract violation ; expected: boolean? ; given: "foo" ; in: the 1st argument of ; (-> boolean? boolean?) ; contract from: (function true?) ; blaming: top-level ; at: readline-input:1.18 ; [,bt for context]
I find define/contract especially useful if I want to check something related to contracts in REPL, where I don't always have a module. However, contract-out is the default recommendation because checking contracts at module boundaries is usually a good choice.
Asumu takikawa
source share