Hi Marc,
>> For contracts, though, (provide (contract-out ...)) gives better error
>> messages than define/contract.
>>
>
> In what sense is this the case, and where can I read more about the
> differences, as well as how to improve errors of contracts?
contract-out gives better error messages than define/contract in the
sense that it has better blame
A define/contract needs to immediately decide who could be blamed for
future errors --- because the new definition can be used right away.
A contract-out can wait until another module requires the definition
--- and tailor its blame errors to different clients.
Here's an example to play with. Submod A provides two functions: f0 is
made with define/contract and f1 with contract-out.
```
#lang racket
(module A racket
(define/contract (f0 x)
(-> natural? natural?)
x)
(define (f1 x)
x)
(provide f0)
(provide (contract-out [f1 (-> natural? natural?)])))
(module B racket
(require (submod ".." A))
(f0 'hello)
#;(f1 'hello))
(require 'B)
```
If B makes a mistake with f0, the error blames submod A.
But if B makes a mistake with f1, the error blames B.
The contract library makes these blame errors internally. I don't
think there's any way to customize short of using `contract` directly.
> <
https://docs.racket-lang.org/reference/attaching-contracts-to-values.html#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._contract-out%29%29>
> uses syntax-property
> <
https://docs.racket-lang.org/reference/stxprops.html#%28def._%28%28quote._~23~25kernel%29._syntax-property%29%29>
> to attach properties to the code it generates that records the syntax of
> the contracts in the fully expanded program. Specifically, the symbol '
> provide/contract-original-contract is bound to vectors of two elements, the
> exported identifier and a syntax object for the expression that produces
> the contract controlling the export."
I was only thinking of the "blaming: ...." part of error messages.
Both define/contract and contract-out can print the whole contract; I
don't think this syntax-property gives contract-out any advantage
(Sadly, the whole contract is sometimes too big to help me find a problem.)