[plt-scheme] rename-out with contract?
David Van Horn wrote:
> Chongkai Zhu wrote:
>> David Van Horn wrote:
>>> Is there an idiomatic way of renaming exports with contracts? For
>>> example:
>>>
>>> #lang scheme
>>> (provide/contract [f (number? . -> . number?)])
>>> (provide (rename-out [f g]))
>>> (define (f n) n)
>>>
>>> I'd like g to be an alias for f, which this does, but I also want g
>>> to have the same contract as f. And I don't want to 1) duplicate
>>> the contract, 2) touch the existing provide/contract form for f.
>>>
>> #lang scheme
>> (define c (number? . -> . number?))
>> (provide/contract [f c])
>> (provide/contract (rename f g c))
>> (define (f n) n)
>
> This violates requirement 2. What I really want is something like
> (rename/contract f g).
If you only want to attach the contract on the module interface, then
it's impossible to meet both requirement 1 and 2.
One option is to you attach the contract to f itself:
#lang scheme
(provide f)
(provide (rename-out [f g]))
(define/contract f
(number? . -> . number?)
(lambda (n) n))
But that means calls to f in the module is also contracted.
Chongkai