1
votes

I am using racket v6.5 repl on linux and trying to run example of take function from the stream tutorial https://docs.racket-lang.org/functional-data-structures/streams.html.

However, instead of expected

> (take 3 (stream 1 2 3 4 5 6))
- : (Rec
 g1827317
 (U Null
    (Boxof (U (Pairof Integer g1827317) (-> (Pairof Integer g1827317))))))
'#&#<procedure:.../pfds/stream.rkt:41:7>

I get

> (take 3 (stream 1 2 3 4 5 6))
take: contract violation
expected: exact-nonnegative-integer?
given: #<stream>
argument position: 2nd
other arguments...:
 3
context...:
 /usr/share/racket/collects/racket/list.rkt:151:0: take
 /usr/share/racket/collects/racket/private/misc.rkt:87:7
> 
1
Are you using the take function from pfds/stream, or the take function from racket/list? You should be using the one from pfds/stream.Alex Knauth

1 Answers

2
votes

To use that stream library, you need to require pfds/stream like this:

(require pfds/stream)

Once you do that, the correct versions of take and stream will be available:

> (require typed/racket)
> (require pfds/stream)
> (take 3 (stream 1 2 3 4 5 6))
- : (Rec
     anonymous-module1715254
     (U Null
        (Boxof
         (U (Pairof Integer anonymous-module1715254)
            (-> (Pairof Integer anonymous-module1715254))))))
'#&#<procedure:.../pfds/stream.rkt:41:7>