Another in-range problem in TR

26 views
Skip to first unread message

Antonio Menezes Leitao

unread,
May 24, 2015, 1:37:07 PM5/24/15
to Racket Dev
Hi,

The following code triggers a type error:

(for ([i (in-range 0 1 1/10)])
  (display i))

Type Checker: type mismatch
  expected: Integer
  given: Exact-Rational in: (for ((i (in-range 0 1 1/10))) (display i))

Note that, in Racket, in-range expect Numbers as arguments (and not Integers).

The following one works fine:

(for ([i (range 0 1 1/10)])
  (display i))

Is this the intended behavior?

Best,
António.

Alexander D. Knauth

unread,
May 24, 2015, 1:54:50 PM5/24/15
to Antonio Menezes Leitao, Racket Dev
This happens because for treats in-range specially, so the expanded code doesn’t use in-range at all, and TR doesn’t recognize that it originally came from a use of in-range.

This fixes it:
#lang typed/racket
(for ([i (identity (in-range 0 1 1/10))])
  (display i))

And this also fixes it:
#lang typed/racket
(for ([i (in-range (ann 0 Exact-Rational) 1 1/10)])
  (display i))


--
You received this message because you are subscribed to the Google Groups "Racket Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
To post to this group, send email to racke...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/CAJQmiZXfD_8sTauRy07mY8QA9aQwsT_89o-%3D6u-PE3b9K0GKgw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Vincent St-Amour

unread,
May 25, 2015, 5:59:39 PM5/25/15
to Alexander D. Knauth, Antonio Menezes Leitao, Racket Dev
As Alex said.

The problem is not with `in-range`, but rather with TR's inference
having trouble with the loop in the expansion of `for`.

Asumu has been working on new versions of the `for` forms which should
play nicer with inference. Those should hopefully solve this problem.

Vincent




At Sun, 24 May 2015 13:54:44 -0400,
> https://groups.google.com/d/msgid/racket-dev/4B26BC02-C80B-4EB5-8B51-9474E88B4D84%40knauth.
> org.

Sam Tobin-Hochstadt

unread,
May 25, 2015, 7:22:19 PM5/25/15
to Vincent St-Amour, Alexander D. Knauth, Antonio Menezes Leitao, Racket Dev
I would say that the real problem is simply an un-annotated function
argument. If you add an appropriate annotation for `i`, everything
works. Typed Racket works hard to help when you don't annotate things,
but in general you need to annotate function arguments, and loop
variables are just an instance of that. I don't think rewriting the
`for` macros will get around that problem.

Sam

On Mon, May 25, 2015 at 5:59 PM, Vincent St-Amour <stam...@ccs.neu.edu> wrote:
> As Alex said.
>
> The problem is not with `in-range`, but rather with TR's inference
> having trouble with the loop in the expansion of `for`.
>
> Asumu has been working on new versions of the `for` forms which should
> play nicer with inference. Those should hopefully solve this problem.
>
> Vincent
>
>
>
>
> At Sun, 24 May 2015 13:54:44 -0400,
> Alexander D. Knauth wrote:
>>
>> https://groups.google.com/d/msgid/racket-dev/4B26BC02-C80B-4EB5-8B51-9474E88B4D84%40knauth.
>> org.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "Racket Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
> To post to this group, send email to racke...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/m2r3q4xqrd.wl-stamourv%40ccs.neu.edu.
Reply all
Reply to author
Forward
0 new messages