[racket] weird typed racket error

From: Alexander D. Knauth (alexander at knauth.org)
Date: Mon Jul 14 13:19:46 EDT 2014

On Jul 14, 2014, at 10:19 AM, Sam Tobin-Hochstadt <samth at cs.indiana.edu> wrote:

> This version with `for/fold` works for me:
> 
> (for/fold : (U Index #f) ([k : (U Index #f) #f])
>  ([i : Index (ann (in-range 5) (Sequenceof Index))])
>  i)

I’m not sure what it was then, because I just tried for/fold again and it worked fine.  

> 
> Sam
> 
> On Sun, Jul 13, 2014 at 11:15 PM, Alexander D. Knauth
> <alexander at knauth.org> wrote:
>> 
>> On Jul 13, 2014, at 8:23 PM, Sam Tobin-Hochstadt <samth at cs.indiana.edu> wrote:
>> 
>>> Probably, what's going on here is that `for/last` has a hidden loop
>>> variable that starts off as `#f` and Typed Racket infers that to have
>>> type `False`.
>> 
>> I thought that was the whole point of adding the : (U Index #f), right?  To provide a type for that loop variable?
>> 
>>> 
>>> If that's the case, there's nothing you can really do other than
>>> rewrite this as `for/fold`.
>> 
>> Well, I tried to use for/fold, but it kept telling me to add more type annotations even when I had annotated every
>> little thing that I could.
>> Then I tried reversing the sequences and using for/first (which would work for what I’m doing but not in general),
>> but if I remember correctly that seemed to have the same problem.
>> Then I tried using the reversed sequences with for/or instead of for/first and that worked fine.
>> But If there’s a hidden loop variable starting of as `#f`, then for/or should have the same problem, but for/or works fine.
>> 
>>> 
>>> Sam
>>> 
>>> On Sun, Jul 13, 2014 at 7:57 PM, Alexander D. Knauth
>>> <alexander at knauth.org> wrote:
>>>> For some reason this:
>>>> (for/last : (U Index #f)
>>>>   ([i : Index (ann (in-range 5) (Sequenceof Index))])
>>>>   i)
>>>> Is giving me this error:
>>>> . Type Checker: type mismatch
>>>> expected: False
>>>> given: Index in: (for/last : (U Index #f) ((i : Index (ann (in-range 5) (Sequenceof Index)))) i)
>>>> 
>>>> Why is it expecting False?
>>>> And is there some type annotation I can put somewhere to fix it or anything?
>>>> 
>>>> 
>>>> ____________________
>>>> Racket Users list:
>>>> http://lists.racket-lang.org/users
>> 



Posted on the users mailing list.