gpt4 book ai didi

stream - Racket :采取:违反契约(Contract)

转载 作者:太空宇宙 更新时间:2023-11-03 18:53:36 25 4
gpt4 key购买 nike

我在 Linux 上使用 racket v6.5 repl 并尝试运行流教程中的 take 函数示例 https://docs.racket-lang.org/functional-data-structures/streams.html .

然而,不是预期的

> (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)

一旦你这样做了,take 的正确版本和 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>

关于stream - Racket :采取:违反契约(Contract),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37034911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com