[plt-scheme] define/contract/provide ?

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Sun Mar 21 16:04:07 EDT 2010

On Sun, Mar 21, 2010 at 3:53 PM, Noel Welsh <noelwelsh at gmail.com> wrote:
> On Sun, Mar 21, 2010 at 7:41 PM, Robby Findler
> <robby at eecs.northwestern.edu> wrote:
>>> If so, the only practical difference I can see would be performance:
>>> If say the module code trusts itself and doesn't want to pay the price
>>> for runtime checking. Is that correct, or is there more nuance to
>>> contracts that I'm not yet understanding?
>> That is true but it also affects the granularity of the blame.
>> Finer-grained contract boundaries potentially cost more but give more
>> accurate blame.
> Furthermore, they interact with tail calls; not all contracts can be
> tail recursive. This can change the semantics of your program.
> N.

There are also cases where one wants different invariants inside a
module than out.  For one example, a binary tree module might
constrain an operation such as "append" to accept only balanced trees
from users, while internally "append" might be used for unbalanced
trees that are later "fixed up" and returned as part of some larger

I generally write my provide/contract form first in a module,
representing the "user interface" to the module and specifying the
behavior clients should expect.  I then write the functions (and value
definitions, structure definitions, etc.) below it as the
implementation.  Sometimes the interface and implementation are very
similar, and sometimes the implementation has a lot more to it, but by
writing them separately I never forget the distinction.


Posted on the users mailing list.