球拍:采取:违反合同
Racket: take: contract violation
我在 linux 上使用 racket v6.5 repl 并尝试 运行 来自流教程 https://docs.racket-lang.org/functional-data-structures/streams.html.
的 take 函数示例
然而,与预期相反
> (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>
我明白了
> (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
>
要使用该流库,您需要像这样要求 pfds/stream
:
(require pfds/stream)
> (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>
我在 linux 上使用 racket v6.5 repl 并尝试 运行 来自流教程 https://docs.racket-lang.org/functional-data-structures/streams.html.
的 take 函数示例然而,与预期相反
> (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>
我明白了
> (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
>
要使用该流库,您需要像这样要求 pfds/stream
:
(require pfds/stream)
> (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>