[plt-scheme] Higher-order contracts for variable-arity functions

From: Robby Findler (robby at cs.uchicago.edu)
Date: Fri May 26 11:17:31 EDT 2006

At Thu, 25 May 2006 16:06:15 -0400, "Carl Eastlund" wrote:
> (module foo mzscheme
> 
>   (require (lib "contract.ss"))
> 
>   (provide/contract
>    [all? ([(any/c . -> . boolean?)] (listof any/c) . ->* . [boolean?])])
> 
>   (define (all? . args)
>     (if (null? args)
>         (error 'all? "Requires at least one argument.")
>         (let* ([pred (car args)]
>                [elems (cdr args)])
>           (andmap pred elems))))
> 
>   )
> 
> (require foo)
> (apply all? number? (list 1 2 3 4))
> 
> In the above, all? is given its arguments as a list, and they arrive
> as a list inside the implementation.  Nevertheless, the contract
> system applies a function contract to the first argument.  I am only
> asking for the same thing, but not having to stop after a fixed number
> of positions.  It is not a question of a new mechanism, merely a new
> use of an old mechanism.  If what I am asking for is unsound, then I
> don't see how the above contract isn't unsound by the same argument.

After thinking a little more about this, I think you're right and I
also think that this suggests that ->* is done wrong. The listof in the
second argument should have been implicit.

I'll try to find some time in the not too distant future to try this
all out and figure how to change the contract library.

Thanks,
Robby



Posted on the users mailing list.