[racket] Contracts and submodules

From: Harry Spier (vasishtha.spier at gmail.com)
Date: Thu Nov 29 23:47:44 EST 2012

On Thu, Nov 29, 2012 at 10:55 PM, Robby Findler
<robby at eecs.northwestern.edu> wrote:
> The main value of putting contracts on modules is, in my opinion, that
> you can pinpoint blame.

Contracts also make a great development/debugging tool.  Internally in
my 2d-byte array getters and setters I'm using unsafe-bytes-ref and
unsafe-bytes-set! for speed  but while I'm developing I've put
contracts on these getters and setters to check for array bounds
errors.  I can then remove these contracts when I'm satisfied with the
correctness of my code.

And then to enable/disable contracts you can use the method Mathias
pointed out here.
http://www.mail-archive.com/[email protected]/msg12281.html

Or this behavour of contracts with submodules lets you do it slightly
differently, the top module with contracts and a single submodule that
bypasses those contracts. I.e.

#lang racket ;;some-function.rkt
(provide (contract-out [ident-number (-> number? number?)]))
(define (ident-number x)  x)
(module+ without-contracts
  (provide ident-number)) ;provide functions without contracts

Then for contracts enabled
#lang racket
(require "some-function.rkt")
(ident-number 'a)

For contracts disabled
#lang racket
(require (submod "some-function.rkt" without-contracts))
(ident-number 'a)

Thanks,
Harry Spier

Posted on the users mailing list.