Yep, this works. Of course, it assumes that fibonacci is memoized or
something to give good performance.
#lang typed/racket
(require math
(for-syntax syntax/parse))
(: check-nat (-> Any Any))
(define (check-nat n)
(unless (exact-nonnegative-integer? n)
(raise-argument-error
It looks like you copied the code incorrectly: it should be (module adapter
racket ...), but you have (module adapter racket/stream ...).
To get the special performance you are referring to, you don't want to make
a structure that's a sequence: you need to use `define-sequence-syntax`
with
The adapter submodule does not work, I get the following error (in both
typed and untyped Racket):
fib.rkt:9:0: module: no #%module-begin binding in the module's language
in: (module adapter racket/stream (provide stream-first stream-rest
(rename-out (stream-cons* stream-cons)))
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
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
like
(for ([i (in-naturals)])
(define fib (fibonacci i))
...)
So I thought it would be nice to have an
5 matches
Mail list logo