[racket] contracts ->i optional keyword syntax
On Aug 27, 2014, at 12:22 PM, Kevin Forchione <lysseus at gmail.com> wrote:
>
> #lang racket
>
> (provide (contract-out [foo
> (-> string? list?)])
> (rename-out (foo bar)))
>
> (define (foo n) (list n))
>
> (module+ test
> (require (submod ".."))
> (foo 3)
> (bar "3”))
>
> Here foo violates the contract. Changing the argument to foo to “3” and the argument to bar to 3 shows that bar does not violate the contract. So the contract is bound to foo and not to the rename. Quite interesting!
>
contract-out attaches a contract to foo so when you can call foo on 3, you get an error.
provide also exports foo as bar w/o contract, so you can call it on anything you want.
This is clearly what the words of the program imply, and the semantics of the language gives it to you. No problems!