Closed citrusmunch closed 3 months ago
v8.12 [cs]
mve
(for/sum : Float ([i : Float (in-range 0 1 0.1)]) i)
same output as the following program
(for/sum : Real ([i : Real (in-range 0 1 0.1)]) i)
which returns 5.5.
5.5
string:1:0: Type Checker: type mismatch expected: Flonum given: Zero in: (for/sum : Float ((i : Float (in-range 0 1 0.1))) i) [,bt for context]
the backtrace, if it's useful :)
string:1:0: Type Checker: type mismatch expected: Flonum given: Zero in: (for/sum : Float ((i : Float (in-range 0 1 0.1))) i) location...: string:1:0 context...: /Applications/Racket v8.12/share/pkgs/typed-racket-lib/typed-racket/typecheck/check-below.rkt:130:5: perform-check! /Applications/Racket v8.12/share/pkgs/typed-racket-lib/typed-racket/private/type-annotation.rkt:83:0: get-type/infer /Applications/Racket v8.12/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-let-unit.rkt:381:0: tc/let-values .../private/parse-interp.rkt:643:50 /Applications/Racket v8.12/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-expr-unit.rkt:112:0: tc-expr/check /Applications/Racket v8.12/share/pkgs/typed-racket-lib/typed-racket/private/type-annotation.rkt:83:0: get-type/infer /Applications/Racket v8.12/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-let-unit.rkt:381:0: tc/let-values .../private/parse-interp.rkt:643:50 /Applications/Racket v8.12/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-expr-unit.rkt:112:0: tc-expr/check [repeats 2 more times] .../private/parse-interp.rkt:643:50 /Applications/Racket v8.12/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-expr-unit.rkt:112:0: tc-expr/check /Applications/Racket v8.12/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:724:0: tc-toplevel-form .../private/parse-interp.rkt:643:50 /Applications/Racket v8.12/share/pkgs/xrepl-lib/xrepl/xrepl.rkt:1573:0 /Applications/Racket v8.12/collects/racket/repl.rkt:11:26
from what I can tell, the literal zero in the definition seems to be the issue. The comment a little before seems to acknowledge this as intentional.
https://github.com/racket/typed-racket/blob/26534e7c8c27155cf1aa37e0390599bc5b56040e/typed-racket-lib/typed-racket/base-env/prims.rkt#L523-L528
https://github.com/racket/typed-racket/blob/26534e7c8c27155cf1aa37e0390599bc5b56040e/typed-racket-lib/typed-racket/base-env/prims.rkt#L553
My current workaround is to just use a foldl for now to avoid mangling Real and Float conversions in my actual program. Just making sure I'm not missing an obvious approach.
foldl
Real
Float
Unfortunately this is the racket semantics for for/sum, so this is not fixable.
for/sum
Alrighty, thank you! I'll close this then.
What version of Racket are you using?
v8.12 [cs]
What program did you run?
mve
What should have happened?
same output as the following program
which returns
5.5
.If you got an error message, please include it here.
the backtrace, if it's useful :)
from what I can tell, the literal zero in the definition seems to be the issue. The comment a little before seems to acknowledge this as intentional.
https://github.com/racket/typed-racket/blob/26534e7c8c27155cf1aa37e0390599bc5b56040e/typed-racket-lib/typed-racket/base-env/prims.rkt#L523-L528
https://github.com/racket/typed-racket/blob/26534e7c8c27155cf1aa37e0390599bc5b56040e/typed-racket-lib/typed-racket/base-env/prims.rkt#L553
My current workaround is to just use a
foldl
for now to avoid manglingReal
andFloat
conversions in my actual program. Just making sure I'm not missing an obvious approach.