[racket] Why this contract violation behaviour?
p.s. Contracts are not types.
Even if you use define/contract, you may violate the contract on recursive calls. This is intentional.
On Nov 16, 2012, at 7:13 PM, Matthias Felleisen wrote:
>
> First cut: Contracts check cross-module invariants. That's why they establish boundaries:
>
> http://doc.racket-lang.org/guide/contract-boundaries.html?q=contracts
>
> When a module M provides a function f with a contract, calls w/i M to f are not checked.
>
> Second cut: if you know about contract regions, you can break modules into several contract regions and thus force contract checks within a module.
>
>
>
> On Nov 16, 2012, at 6:59 PM, Harry Spier wrote:
>
>> Dear list members,
>>
>> Can someone explain why in the following cases only two out of the three cases and not all of them cause a contract violation.
>> Thanks,
>> Harry Spier
>>
>> #lang racket
>> (provide/contract (amount positive?))
>> (define amount -7)
>>>
>> contract
>> promised: positive?
>> produced: -7
>> in: positive?
>> contract from: anonymous-module
>> blaming: anonymous-module
>>
>> BUT--------------------------------------
>>
>> #lang racket
>> (provide/contract [amount (-> positive?)])
>> (define (amount) -7)
>> (amount)
>>>
>> No contract violation
>>
>> AND-------------------------------------------
>>
>> #lang racket
>>
>> (provide/contract [amount (-> positive?)])
>> (define (amount) -7)
>>
>> (module* main racket
>> (require (submod ".."))
>> (amount))
>>
>>>
>> amount: broke its contract
>> promised: positive?
>> produced: -7
>> in: the range of
>> (-> positive?)
>> contract from:
>> c:\users\harry\ocr_project\contract-test.rkt
>> blaming:
>> c:\users\harry\ocr_project\contract-test.rkt
>> at: c:\users\harry\ocr_project\contract-test.rkt:3.20
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4373 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20121116/a5aa4845/attachment.p7s>