[plt-scheme] Question on ill-defined contract

From: Paulo J. Matos (pocm at soton.ac.uk)
Date: Tue Jun 5 16:45:59 EDT 2007

Hi all,

Today while I was doing a demo on PLT Scheme I hit something I was a
bit wordless (why does it happen every time were presenting
something?).
I defined a function (something along these lines):
foo.scm
(module foo mzscheme

  (define (foo-fn a b c)
      (+ a b c))

  (provide/contract
   [foo-fn (integer? integer? integer? . -> . integer?)]))

Then since the only interesting parameter was a, b was by default 0
and c was by default a + 5, I changed it to a opt-lambda:
  (define foo-fn
    (opt-lambda (a (b 0) (c (+ a 5)))
      (+ a b c)))

But I forgot to update the contract, when I went to show everyone from
module bar, how opt-lambda would work nicely, I have:
(module bar mzscheme
  (require "foo.scm")
  (foo-fn 5))

and I get:
procedure foo-fn: expects 3 arguments, given 1: 5

The triggered question by the host of the demo was indeed intriguing.
Shouldn't the contract be broken? Should I get some kind of error
helping me to spot that the error was in the contract definition?
When I click the bug I even get a decent error message. Is this a bug
or a 'feature'?

Cheers,
-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK


Posted on the users mailing list.