[racket] Another basic TR question
On Feb 13, 2014, at 2:56 PM, Vincent St-Amour wrote:
> At Thu, 13 Feb 2014 14:45:08 -0500,
> Bloch Stephen wrote:
>> Don't tell me the Zero I'm running into is the initial value of
>> for/sum's hidden accumulator....
>
> Yes, that's where the Zero comes from.
>
>> And even if there were a zero, shouldn't Zero be a subtype of Flonum?
>
> Zero is the type of the exact integer 0, but the Flonum type only
> includes floating-point numbers. The two are not related by subtyping.
Yes, actually I figured that part out... but why is the accumulator initialized to something that might be the wrong type?
> You can use `assert' to check, at run-time, that you do always get a
> Flonum:
>
> (assert (for/sum: : Real [[ii : Index 300]]
> pi)
> flonum?)
>
> This expression typechecks at type Flonum.
Hmm. So just changing the annotation type from Flonum to Real does the trick?
for/sum: initializes its accumulator to an exact 0, which is of type Zero, which is a subtype of Real but not of Flonum.
It then adds pi, which is a Flonum, which is also a subtype of Real, and it has no problem proving the answer to be a Real (just not a Flonum). Even though AFAIK anything plus a Flonum produces either a Flonum or an error.
I'm so confused....
Anyway, thanks!
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/b7cc76da/attachment.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/b7cc76da/attachment.sig>