[racket] typing a function

From: Pierpaolo Bernardi (olopierpa at gmail.com)
Date: Thu Nov 22 11:55:26 EST 2012

On Thu, Nov 22, 2012 at 4:41 PM, Neil Toronto <neil.toronto at gmail.com> wrote:
> On 11/22/2012 07:41 AM, Pierpaolo Bernardi wrote:

> (: make-array (Positive-Index Positive-Index -> Array2))
> (define (make-array xdim ydim)
>   (for/vector: : Array2 ((i (in-range xdim)))
>     (ann (make-vector ydim 0) (Vectorof Number))))
>
> Here, `ann' means "annotate this expression with this type".

I had tried the ann.

> Probably the main trick in working with TR is knowing how and when to help
> it figure out expressions' types. I've learned to avoid giving loop
> variables types, for example. Doing so requires guessing what the `in-range'
> macro expands to. (FWIW, in this case, Nonnegative-Fixnum is the most
> restricted type `i' can have.)

Duh.  Big thinko (in my defense I can say that I added the annotation
only as a last effort to make TR happy).

> To sum up: upgrade, because we made the computer less stupid in 5.3.1, and
> learn a few rules of thumb about when and how to annotate.

Downloading 5.3.1 now.

> One more thing. Are you writing an array library for your own use, or as an
> exercise? The next Racket release will have an array data type.

I'm only porting an old Racket program to TR as an exercise in learning TR.

Thanks. Your explanations are very much appreciated.

Cheers
P.

Posted on the users mailing list.