[racket] how to improve performance by streamlining imports?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Feb 21 21:00:44 EST 2014

On Feb 21, 2014, at 2:38 PM, Matthew Butterick wrote:

>> Rewriting to avoid a dependency does work, but usually only if you can
>> avoid some large subsystem (such as the contract system) completely.
> 
> 
> Contracts are a good example. Here's the vexing pattern that I've run into frequently


Perhaps you want to organize your programs in something like this fashion: 

#lang racket

(module server racket
  
  (provide
   (contract-out
    (f (natural-number/c . -> . natural-number/c))))
  
  (module fast-server racket
    (provide 
     ;; Nat -> Nat 
     f)
    
    (define (f i)
      (- i 1)))
  
  (require (submod "." fast-server)))

(module safe-client racket
  (require (submod ".." server))
  (with-handlers ((exn:fail:contract? (compose displayln exn-message)))
    (displayln (f 0))))

(module fast-client racket
  (require (submod ".." server fast-server))
  (displayln (f 0)))

(require 'safe-client)
(require 'fast-client)


Posted on the users mailing list.