[plt-dev] abstract contracts

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Fri Sep 4 14:00:08 EDT 2009

I've added #:exists to provide/contract, as a way to hide information
ala "type t" declarations on ML signatures.

See the contracts section in the Guide for a worked example and a
discussion of a gotcha. The short version is that you can now write
things like this:

(provide/contract
  #:exists stack
  [new stack]
  [push (-> int stack stack)]
  [pop (-> (and/c stack non-empty?) int)]
  [non-empty? (-> stack boolean?)])

and have the contract system enforce data abstraction, even if your
stack operations are simply these:

  (define new '())
  (define push cons)
  (define pop car)
  (define non-empty? pair?)

That is, clients of your module will not be able to treat your stacks
as if they were lists, even though they really are lists.

Robby


Posted on the dev mailing list.