[racket] Another basic TR question

From: Bloch Stephen (bloch at adelphi.edu)
Date: Thu Feb 13 16:22:35 EST 2014

On Feb 13, 2014, at 2:51 PM, Sam Tobin-Hochstadt wrote:

>> (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.

Doesn't that make for/sum: useless for anything other than exact integers?

Couldn't for/sum: initialize its accumulator to a Real-Zero rather than the overly-specified type Zero?  (That would rule out complexes, but it would be a big step in the right direction.)  (Should there be a Complex-Zero type?)

Even better, could for/sum: look at the annotation type and decide what initial value (0 or #i0.0) to use?

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

OK, I'll try that.


Stephen Bloch
sbloch at adelphi.edu
GPG  key at http://adelphi.edu/sbloch/sbloch.pubkey.asc

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140213/cb67e317/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 495 bytes
Desc: This is a digitally signed message part
URL: <http://lists.racket-lang.org/users/archive/attachments/20140213/cb67e317/attachment-0001.sig>

Posted on the users mailing list.