#lang racket

(module x racket
  (provide
   (contract-out 
    (rename f g (-> integer? any/c))))
  
  (define f displayln))

(require 'x)

(g 'a)




On Aug 27, 2014, at 2:18 PM, Kevin Forchione <[email protected]> wrote:

> 
> On Aug 27, 2014, at 11:12 AM, Matthias Felleisen <[email protected]> wrote:
> 
>> 
>> On Aug 27, 2014, at 12:22 PM, Kevin Forchione <[email protected]> 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!
> 
> Yes, I agree. Very useful! Is there a way to attach a contract to a renamed 
> identifier? I tried wrapping contract around a rename form and it didn’t 
> appear to like it.
> 
> -Kevin
> 


____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to