[racket] TR Submodules

From: Neil Toronto (neil.toronto at gmail.com)
Date: Sun Nov 18 21:39:43 EST 2012

On 11/18/2012 07:02 PM, Ray Racine wrote:
> #lang typed/racket
>
> (provide x)
>
> (module M typed/racket
>    (provide x)
>    (define: x : Natural 3))
>
> (require (submod "."  M))
>
> ;; end-of-file
>
>...
>
> Has anyone had a chance to look into this yet?  I'd love to use
> submodules in TR.

As a workaround, you can change the parent module's language to "racket" 
and your specific example will work just fine. You don't have to worry 
about extra contract checks, because the identifier `x' won't have a 
contract on it unless it's used in untyped code, even though it's 
provided by untyped code.

IOW, if your parent module above is named "x.rkt", you can write this:

#lang typed/racket
(require "x.rkt")
x


TR is smart enough to not put a contract on `x'. (I don't think it would 
in this case anyway, but pretend `x' is a function. It still wouldn't 
have a contract.)

The array library uses typed submodules a lot, mostly to define typed 
values and untyped macros that expand to those values in the same file. 
I did have to split files in a few cases, because I ran into problems 
having two typed submodules in the same parent module.

I'll let someone else explain that fundamental problem that seems to 
require rewriting the macro expander to fix it. I also won't speculate 
on whether that will happen soon.

Neil ⊥


Posted on the users mailing list.