Mysterious multiple values in a typed-racket program

17 views
Skip to first unread message

Hendrik Boom

unread,
May 9, 2020, 11:38:45 AM5/9/20
to Racket Users
I get the message

readspec.rkt:195:8: Type Checker: Expression should produce 3 values, but produces 1 values of types String in: (for/set : (Setof String) (((l : String) (cast (in-lines input-port) (Sequenceof String)))) (cast (string-trim l) String))

from the following function:

(define (read-manpages [input-port : Input-Port])
(cast (for/set : (Setof String) (([l : String] (cast (in-lines input-port) (Sequenceof String))))
(cast (string-trim l) String))
(Setof String)))

The expression it is complaining about is the (for/list ......) construction.

I'm trying to covert a Racket program to a typed Racket program.
As far as I can see, this function reads words, one to a line, from
input-port and makes a set of these words.

It baffles me where the type checker gets the idea that 3 values are wanted
anywhere.

I put in a lot of casts just to make sure I knew what types it had to work
with.

The original code, without types:

(define (read-manpages input-port)
(for/set ((l (in-lines input-port)))
(string-trim l)))

Any ideas?

-- hendrik

Ben Greenman

unread,
May 9, 2020, 12:24:21 PM5/9/20
to Racket Users
Well this is unfortunate.

`(l : String)` should be `l : String` with no parentheses

The code you have looks like this to Typed Racket:

```
(for/set : TYPE
(((val0 val1 val2) (in-lines input-port)))
LOOP-BODY)
```

Hendrik Boom

unread,
May 9, 2020, 2:10:45 PM5/9/20
to Racket Users
Got it. It's confusing whenyuo need the parentheses around a type-binding and
when you don't.

-- hendrik

>
> The code you have looks like this to Typed Racket:
>
> ```
> (for/set : TYPE
> (((val0 val1 val2) (in-lines input-port)))
> LOOP-BODY)
> ```
>
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAFUu9R7wBS_hbZpXmFR097qxi8F-54rkogEXe6R0Nyqp_iMqDQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages