Combining generators and typed racket

41 views
Skip to first unread message

Nate Griswold

unread,
Jul 21, 2020, 9:45:41 PM7/21/20
to Racket Users
Do generators and typed racket work together well? It seems (yield) doesn't have a type and i couldn't get my module to work.

Is there a way to make some procedure untyped in the middle of a typed file? Is it just best to break these things into separate files?

Thank you

Nate

Nate Griswold

unread,
Jul 22, 2020, 12:15:09 AM7/22/20
to Racket Users
Actually, is there any way at all to use lazy lists of things (streams or generators) in typed racket?

Nate

Sam Tobin-Hochstadt

unread,
Jul 22, 2020, 2:56:14 PM7/22/20
to Nate Griswold, Racket Users
Currently, neither `racket/stream` nor `racket/generator` are
supported by Typed Racket, unfortunately.

Sam
> --
> 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/CAM-xLPo_c3LzL81Qv6bA2zzJMhQftQ46JR%3DWyZdSJjPJ9rYM5Q%40mail.gmail.com.

Nate Griswold

unread,
Jul 22, 2020, 3:22:36 PM7/22/20
to Sam Tobin-Hochstadt, Racket Users
Ok, thanks for the reply.

I was trying to use this function:

(define (iterate f)
  (yield (f))
  (iterate f))

But it seems the only thing i can do is have a separate (calling it "-untyped.rkt") module and putting anything that requires iterate in there.

Are there any papers that would be helpful in trying to address this implementation-wise?

Nate

Nate Griswold

unread,
Jul 22, 2020, 3:24:04 PM7/22/20
to Sam Tobin-Hochstadt, Racket Users
Also can you think of a better way to do this than my implementation of iterate? The use case is putting it in a for loop along with a break or a finite list.

Nate

Sam Tobin-Hochstadt

unread,
Jul 22, 2020, 4:27:46 PM7/22/20
to Nate Griswold, Racket Users
To implement support for this, you would mostly need to add types for
the relevant functions -- but those functions are the ones that
generators (or streams) expand to. For generators, the key ones look
to be `create-generator` and `yield`. `create-generator` is not
exported, so you'd have to add the type in
`typed-racket/base-env/base-special-env`. `yield` can be given a type
in `typed-racket/base-env/base-env`. The tricky part will be figuring
out what those types should be.

I'm happy to answer more questions about adding this.

Sam

On Wed, Jul 22, 2020 at 3:22 PM Nate Griswold <nategr...@gmail.com> wrote:
>
> Ok, thanks for the reply.
>
> I was trying to use this function:
>
> (define (iterate f)
> (yield (f))
> (iterate f))
>
> But it seems the only thing i can do is have a separate (calling it "-untyped.rkt") module and putting anything that requires iterate in there.
>
> Are there any papers that would be helpful in trying to address this implementation-wise?
>
> Nate
>
>
> On Wed, Jul 22, 2020 at 1:56 PM Sam Tobin-Hochstadt <sa...@cs.indiana.edu> wrote:
>>
Reply all
Reply to author
Forward
0 new messages