[racket] Another basic TR question

From: Sam Tobin-Hochstadt (samth at cs.indiana.edu)
Date: Thu Feb 13 14:51:55 EST 2014

On Thu, Feb 13, 2014 at 2:45 PM, Bloch Stephen <bloch at adelphi.edu> wrote:
> I've removed a lot of possibly-irrelevant stuff and boiled my current
> obstacle down to the following:
>
> In #lang racket, the following works fine:
>
> (for/sum [[ii 300]]
>   pi)
>
>
>
> In #lang typed/racket, I try to do the same thing:
>
> (for/sum: : Flonum [[ii : Index 300]]
>   pi)
>
> and I get the type error "Expected Flonum, but got Zero".  Where is there a
> zero anywhere in this code?  And even if there were a zero, shouldn't Zero
> be a subtype of Flonum?
>
> Don't tell me the Zero I'm running into is the initial value of for/sum's
> hidden accumulator....

Unfortunately, that's exactly what I'm going to tell you.  Typed
Racket isn't smart enough to know that the initial value is never
used, and so 0 is thought to be a possibility.

I recommend using `for/fold` for this case as a workaround.

Sam

Posted on the users mailing list.