[plt-scheme] Contracts on Libraries

From: Matt Jadud (jadudm at gmail.com)
Date: Sat May 26 15:36:13 EDT 2007

[Oops. Failed to reply to the list...]

On 5/26/07, Joe Marshall <jmarshall at alum.mit.edu> wrote:
> It seems to me that a similar technique could be used with contracts.

I think, actually, the better way is through the module export
mechanism. At least, this is always how I assumed I would do it if I
had a library where the presence of contracts made a significant
difference. This way, I could use foo/c everywhere (to get the
contracts), but use foo/nc when I was confident that the contracts
were not necessary.

Or something like that.


(module foo mzscheme
 (provide a)
 (define (a x) 3))

(module foo/c mzscheme
 (require (lib "contract.ss"))
 (require (prefix foo: foo))
 (provide/contract (rename foo:a a (-> number? number?)))

(module foo/nc mzscheme
 (require foo)
 (provide (all-from foo)))

(require foo/nc)
;; This works, and returns 3, because there are no contracts
(a 'x)

(require foo/c)
;; This fails for contractual reasons
(a 'x)

Posted on the users mailing list.