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

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Thu May 25 15:26:31 EDT 2006

On 5/25/06, Robby Findler <robby at cs.uchicago.edu> wrote:
> listof cannot accept higher-order contracts, due to the presence of
> mutation. The tricky case is that someone hands you the list and, at
> that point, the contract is check and the functions inside the list are
> wrapped. Now, imagine that someone mutates the list -- what happens?
> How do the contracts get onto the new functions in the list? (We could
> change mutation operator, but we haven't taken that step ... yet)
> Note that if you could use immutable lists, that would work fine.
> Maybe time to petition any nearby R6RS committee members? ;)

My point is that I don't care about the list.  I care about the
function arguments.  I want to apply a function contract to each
argument to my function.  If they get taken out of the list, or other
values get put into the list, I don't care, because the list itself
was only a convenient delivery mechanism for my many arguments.

So, for instance, could we have a function contract like the following:

(var-> [contract ...] contract contract)

The first list of contracts constrain the function's required
arguments.  The contract in the second position is applied to each
subsequent argument, if any.  The contract in the third position is
applied to the function's result.  (This could have alternate forms
for dependent arguments and multiple return values.)

Then I could write:
  [compose ([(any/c . -> . any/c)] (any/c . -> . any/c) . var-> .
(any/c . -> . any/c))]

Carl Eastlund
"Cynical, but technically correct."

Posted on the users mailing list.