From fb818abb2ddb8e4dc8d1ed8bb1794a7cb75b28ff Mon Sep 17 00:00:00 2001 From: Matthias Felleisen Date: Tue, 21 May 2019 09:05:12 -0400 Subject: [PATCH] added unprotected-submodule hint, but also sent query to Robby --- .../scribblings/style/some-performance.scrbl | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pkgs/racket-doc/scribblings/style/some-performance.scrbl b/pkgs/racket-doc/scribblings/style/some-performance.scrbl index c9a1a33fe5..3432c79e2d 100644 --- a/pkgs/racket-doc/scribblings/style/some-performance.scrbl +++ b/pkgs/racket-doc/scribblings/style/some-performance.scrbl @@ -155,6 +155,9 @@ in the outer module that re-exports the desired pieces of functionality.} ] +The @racket[contract-out] facility accommodates this strategy via its +@racket[#:unprotected-submodule] functionality. + @margin-note*{We will soon supply a Reference section in the Evaluation Model chapter that explains the basics of our understanding of ``safety'' and link to it.} @; @@ -292,6 +295,43 @@ the left one requires just @tt{fast} and the right one the submodule called contracts; the right one imports the same function without contract and thus doesn't have to pay the performance penalty. +Here is a concise way of implementing the same strategy via +@racket[contract-out]: + +@;% +@(begin +#reader scribble/comment-reader +(racketmod0 #:file + @tt{modern} + racket + + (define state? ...) + (define action? ...) + (define strategy/c + (-> state? action?)) + + (provide + (contract-out + #:unprotected-submodule no-contract + ;; people's strategy + (human strategy/c) + + ;; tree traversal + (ai strategy/c))) + + (code:comment #, @1/2-line[]) + (code:comment #, @t{implementation}) + + (define (general p) ... ) + + (define human + (general create-gui)) + + (define ai + (general traversal)))) + + + In some cases, the presence of contracts prevents a module from being used in a context where contracts aren't available, say, for @rkt/base[] or the contracts library itself. Again, you may wish you had the same library