[racket-dev] supplying typed and untyped entry points, take 2

From: Neil Toronto (neil.toronto at gmail.com)
Date: Tue Dec 18 01:47:40 EST 2012

IIRC, one of your ideas was to expand module code to a typed and an 
untyped submodule, and have them provide the same identifiers. Somehow - 
doesn't matter exactly for now - untyped clients would get the untyped 
identifiers, and typed clients would get the typed identifiers.

I've had some experience doing something similar with macros. A good 
example is the `in-array' macro, defined in 
"math/private/array/array-sequence.rkt". Here's part of the expansion of 
(in-array arr-expr):

   (plet: (A) ([arr : (Array A)  arr-expr])
     (cond [(array? arr)
            (define ds (array-shape arr))
            (define dims (vector-length ds))
            (define size (array-size arr))
            (define proc (unsafe-array-proc arr))
            (define: js : Indexes (make-vector dims 0))
            (values ds size dims js proc)]
           [else
            (raise-argument-error 'in-array "Array" arr)]))

It's kind of annoying to have to keep in mind that the macro will be 
expanded in both typed and untyped contexts. In this case - and this is 
pretty typical - the expanded code has to ensure that it gets an array 
in two different ways. One is (plet: (A) ([arr : (Array A)  arr-expr]) 
...) for Typed Racket. The other is (cond [(array? arr) ...] [else ...]) 
for untyped Racket.

One sort of nice thing is that TR's optimizer erases the `else' branch. 
I don't think it can erase the expression (array? arr), though. Also, 
the type annotations mean nothing in untyped Racket, so it's kind of 
like they get erased.

I could see writing a few modules like this, especially with help from 
some good macros.

The thing I worry about most is that a struct type would have two 
different definitions, typed and untyped, which would be different 
struct types at run time. In particular, an array created in a Typed 
Racket client couldn't be sent to an array-accepting function defined in 
an untyped client. That seems like a deal-breaker, and I can't think of 
an easy way around it.

Neil ⊥

On 12/17/2012 06:34 PM, Matthias Felleisen wrote:
>
>
> Begin forwarded message:
>
>> From: Matthias Felleisen <matthias at ccs.neu.edu>
>> Subject: Re: [racket-dev] Typed versions of untyped collections
>> Date: December 17, 2012 6:44:19 PM EST
>> To: Neil Toronto <neil.toronto at gmail.com>
>> Cc: dev at racket-lang.org
>>
>>
>> Okay. I propose we figure out how to allow people programming in Typed Racket,
>> and deploy two copies of the code without performance overhead for either T or U
>> code.
>>
>>
>> _________________________
>>   Racket Developers list:
>>   http://lists.racket-lang.org/dev
>
>
> _________________________
>    Racket Developers list:
>    http://lists.racket-lang.org/dev
>


Posted on the dev mailing list.