[racket] Typed macros in untyped code

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Thu Nov 18 19:54:49 EST 2010

On Thu, Nov 18, 2010 at 7:48 PM, Neil Toronto <neil.toronto at gmail.com> wrote:
> Why aren't typed macros allowed to be used in untyped code? Don't the
> annotation forms like (: ...) expand to no-ops?

This is an important limitation - the typed macros have access to the
unprotected versions of the typed identifiers from the module, so they
can't be allowed to escape.  There are plans to evolve the certificate
system so that we can lift this restriction, but that's future
research.

> I've been able to work around this apparently artificial limitation by
> defining typed macros in #lang racket modules where I required typed/racket.
> I could even re-export the macros in typed modules, import the re-exported
> macros in untyped modules, and use them. The macros can even expand to code
> that uses (: ...), and untyped code that uses the macros still works.
>
> But Typed Racket craps on me if I use the typed macros inside a sandbox in
> Scribble. For example, using @(example #:eval my-eval (bftest-error (bfexp
> (bf 2)))) gives me this:
>
>> (bftest-error (bfexp (bf 2)))
>  eval:63:0: Type Checker: Macro bftest-error from typed
>  module used in untyped code in: (bftest-error (bfexp (bf
>  2)))
>
> Gah! I thought I got around this! How do I convince Typed Racket or the
> sandbox that I'm not up to anything funny?

Require `#%top-interaction' from typed racket, or in general create
your sandbox from Typed Racket.

-- 
sam th
samth at ccs.neu.edu


Posted on the users mailing list.