[plt-scheme] Questions about contracts

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Apr 16 21:36:05 EDT 2007

At Mon, 16 Apr 2007 17:16:20 -0600, "Chongkai Zhu" wrote:
> Let's say the SVN  Revision 3591 of SRFI 63 
> (http://svn.plt-
> scheme.org/view/trunk/collects/srfi/63/63.ss?revision=3591&pathrev=5900).
> 
> The contract of make-shared-array is:
> 
>    (make-shared-array
>     (->r ((array array?)
>           (mapper (->* () (listof natural-number/c)
>                        ((listof natural-number/c)))))
>          indices (listof natural-number/c)
>          array?))
> 
> which looks fine.

Not to me!

The above contract (and the error message) says that the second
argument to `make-shared-array' must be a function that accepts any
number of arguments. Such a contract empowers `make-shared-array' to
call the given function with, say, 4 arguments, then 0 arguments, then
2 arguments, all before returning --- independent of the other
arguments to `make-shared-array'.

The actual `make-shared-array', however, merely expects the function to
accept the same number of arguments as supplied indices. That's very
different than requiring the function to accept any number of
arguments.

I must admit that I don't know offhand how to write the actual contract
down; that's probably my lack of expertise with the contract library.
Meanwhile, the only bug I see is that the contract above is way too
strict. I don't see a bug in the implementation of contracts.

Matthew



Posted on the users mailing list.