[plt-scheme] Contract Error Message

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Mon Jul 20 14:28:40 EDT 2009

On Mon, Jul 20, 2009 at 2:22 PM, Paulo J. Matos<pocmatos at gmail.com> wrote:
> Hi all,
>
> I found an error message in a contract pretty strange and took me ages
> to understand my contract was wrong. However, it is strange that I get
> this message that provides no clue to the error. An example of the
> problem:
> #lang scheme/load
>
> (module hello scheme
>  (define (xpto n)
>    (build-list 10 (lambda (n) n)))
>
>  (provide/contract
>   [xpto ((or symbol? string?) . -> . (listof (or/c (symbol? string?))))]))
>
> (module caller scheme
>  (require 'hello)
>
>  (xpto 'hello))
>
> The error:
>> (require 'caller)
> . 'hello broke the contract
>  (-> symbol? (listof (or/c #f)))
>  on xpto; expected <(listof (or/c #f))>, given: (0 1 2 3 4 5 6 7 8 9)
>
> The contract  (listof (or/c #f)) confused me because I had no such
> contract. Only after a lot of digging I found that I had an extra set
> of parenthesis around the args in xpto contract: (or/c (symbol?
> string?))
>
> Is it possible to improve this?

What you wrote was a perfectly acceptable contract that functioned
perfectly, except that it wasn't the one you meant it to be.  What
alternate behavior would you propose?

--Carl


Posted on the users mailing list.