gpt4 book ai didi

haskell - 在定义之前使用符号

转载 作者:行者123 更新时间:2023-12-03 14:57:38 25 4
gpt4 key购买 nike

为什么在等式右侧的下面一行中可以使用符号“fibs”,尽管它尚未定义:

let fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

最佳答案

关键是fibs的定义

fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

直到在其他地方使用才被评估。然后使用已知部分展开定义。我们从 fibs = 0 : 1 : ??? 开始.然后,如果需要第三个元素,则进一步评估定义,
fibs = 0 : 1 : zipWith (+) (0 : 1 : ???) (tail (0 : 1 : ???))
= 0 : 1 : zipWith (+) (0 : 1 : ???) (1 : ???)
= 0 : 1 : (0 + 1) : zipWith (+) (1 : ???) (???)

但是未知的部分 ???部分已知,已确定为 ??? = 1 : ???? ,所以展开可以继续,
     = 0 : 1 : 1 : zipWith (+) (1 : 1 : ????) (1 : ????)
= 0 : 1 : 1 : 2 : zipWith (+) (1 : ????) (????)
-- now ???? is known to be 2:?????
= 0 : 1 : 1 : 2 : zipWith (+) (1 : 2 : ?????) (2 : ?????)

等等

关于haskell - 在定义之前使用符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9864137/

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