no TR support for streams?

47 views
Skip to first unread message

John Clements

unread,
Sep 6, 2019, 1:04:09 PM9/6/19
to Racket Users
Perhaps I just don’t know how to search the racket docs correctly, but IIUC there’s no support for Streams in the current TR implementation? I just want to use stream-cons, empty-stream, stream-first, and stream-rest. I guess the easy workaround is just to use thunks to roll my own stream, but I’m wondering if I’m missing something obvious?

John

Alex Knauth

unread,
Sep 7, 2019, 5:23:44 PM9/7/19
to John Clements, Racket Users
On Sep 6, 2019, at 1:04 PM, 'John Clements' via Racket Users <racket...@googlegroups.com> wrote:

Perhaps I just don’t know how to search the racket docs correctly, but IIUC there’s no support for Streams in the current TR implementation? I just want to use stream-cons, empty-stream, stream-first, and stream-rest. I guess the easy workaround is just to use thunks to roll my own stream, but I’m wondering if I’m missing something obvious?

You can wrap `stream-cons`, etc. in contracts and keep the original stream data type, but it's trickier than wrapping a normal function, and involves:
 - an untyped file which imports the macros and exports "function-ized" versions of the macros
 - a typed file which imports those function-ized things with require/typed, then exports new versions of the macros in terms of the functions

And looks something like like these two files:
; untyped-stream-function-ized.rkt
#lang racket
(provide stream-cons/fn)
(require racket/stream)
(define (stream-cons/fn a b)
  (stream-cons (a) (b)))

; typed-stream.rkt
#lang typed/racket
(provide stream-cons)
(require/typed "untyped-stream-function-ized.rkt"
  [stream-cons/fn (All (a) (-> (-> a) (-> (Sequenceof a)) (Sequenceof a)))])
(define-simple-macro (stream-cons a b)
  (stream-cons/fn (thunk a) (thunk b)))

This is the strategy I used for my `typed-racket-stream` repository:

I wanted to do this instead of "rolling my own" stream library because I wanted to be able to share the same stream data-structure as existing untyped racket files.

Alex Knauth

John Clements

unread,
Sep 10, 2019, 6:42:25 PM9/10/19
to Alex Knauth, Racket Users
Oh! and in fact, you already bundled it as a pkg: https://pkgs.racket-lang.org/package/typed-racket-stream

Thanks!

John
> --
> 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/50960124-B18A-445F-9511-5899E60D9A86%40knauth.org.



Reply all
Reply to author
Forward
0 new messages