[racket] weird behavior with in-range in typed racket
This is because Racket’s for loops special-case on in-range, in-list, in-vector, etc. They do this for performance reasons—no need to check the type at runtime. This is probably redundant in a typed context, anyway, though, since the typechecker should be able to (ideally) make those optimizations itself.
Anyway, it looks like the TR expansion of for loops doesn’t account for the (rather large) type of in-range. I think Asumu’s rewriting the loops in TR, though—perhaps this will be fixed then?
> On Feb 5, 2015, at 19:07, Alexander D. Knauth <alexander at knauth.org> wrote:
>
> This program:
> #lang typed/racket
> (define n : Real 5)
> (for/list ([i : Natural (in-range n)]) : (Listof Natural)
> i)
> And this program:
> #lang typed/racket
> (define n : Real 5)
> (for/list ([i : Natural (identity (in-range n))]) : (Listof Natural)
> i)
> The first one produces an error:
> . Type Checker: type mismatch
> expected: Nonnegative-Integer
> given: Integer in: (for/list ((i : Natural (in-range n))) : (Listof Natural) i)
> The second one works fine:
> '(0 1 2 3 4)
> But why does the first one produce integer, but wrapping it in identity make it produce Nonnegative-Integer (Natural) ?
>
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150205/d3ff276d/attachment.html>