[plt-scheme] Contract Error Message

From: Paulo J. Matos (pocmatos at gmail.com)
Date: Mon Jul 20 14:22:29 EDT 2009

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?

-- 
Paulo Jorge Matos - pocmatos at gmail.com
http://www.pmatos.net


Posted on the users mailing list.