gpt4 book ai didi

haskell - 为什么 "++"功能比 ":"贵得多?

转载 作者:行者123 更新时间:2023-12-01 22:05:15 25 4
gpt4 key购买 nike

<分区>

以下这段话来自Learn You a Haskell for Great Good!

"Watch out when repeatedly using the ++ operator on long strings. When you put together two lists (even if you append a singleton list to a list, for instance: [1,2,3] ++ [4]), internally, Haskell has to walk through the whole list on the left side of ++. That's not a problem when dealing with lists that aren't too big. But putting something at the end of a list that's fifty million entries long is going to take a while. However, putting something at the beginning of a list using the : operator (also called the cons operator) is instantaneous."

我不知道为什么 Haskell 必须遍历++ 左侧的整个列表。

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