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 sbl...@adelphi.edu GPG key at http://adelphi.edu/sbloch/sbloch.pubkey.asc
PGP.sig
Description: This is a digitally signed message part
____________________ Racket Users list: http://lists.racket-lang.org/users