I hope there's a better way, but this works. The adapter submodule is
needed because the normal `stream-cons` is a macro that expands into some
private things that don't have types, and it requires that the rest
expression produce a stream, not just any sequence. Note also, if you
haven't worked with `racket/stream` before, that the arguments to the
normal `stream-cons` are evaluated lazily.
(module adapter racket
(rename-out [stream-cons* stream-cons]))
(define (stream-cons* make-first make-rest/seq)
[stream-first (All (A) (-> (Sequenceof A) A))]
[stream-rest (All (A) (-> (Sequenceof A) (Sequenceof A)))]
[stream-cons (All (A) (-> (-> A)
(-> (Sequenceof A))
(: fibonacci (Sequenceof Integer))
(λ () 0)
(stream-cons (λ () 1)
(let calculate : (Sequenceof Integer) ([fibonacci
(stream-cons (λ ()
(+ (stream-first fibonacci)
(λ () (calculate (stream-rest
(for/list : (Listof Integer) ([fib fibonacci]
[i (in-range 10)])
On Sun, Apr 22, 2018 at 3:01 AM, HiPhish <hiph...@openmailbox.org> wrote:
> Hello Racketeers,
> I have been playing around with the `math/number-theory` package and I
> wanted to use a `for`-loop of Fibonacci numbers. I had to write something
> (for ([i (in-naturals)])
> (define fib (fibonacci i))
> So I thought it would be nice to have an `in-fibonacci` sequence.
> According to the Racket reference  one can implement a custom sequence
> using structure type properties, but according to the Typed Racket guide
>  structure type properties are not supported in Typed Racket. Is there
> any other way to get `in-fibonacci` into the module or should I just live
> without it?
>  https://docs.racket-lang.org/reference/sequences.html?q=sequences
>  https://docs.racket-lang.org/ts-guide/caveats.html#%28part.
> 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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
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
For more options, visit https://groups.google.com/d/optout.