我是 Haskell 的新手,我正在为我的编程语言课写一篇关于它的论文。我想用一些示例代码来展示 Haskell 的懒惰,但我不确定我所看到的是否真的是懒惰。
doubleMe xs = [x*2 | x <- xs]
在 ghci 中:
let xs = [1..10]
import Debug.Trace
trace (show lst) doubleMe (trace (show lst) doubleMe (trace (show lst) doubleMe(lst)))
输出:
[1,2,3,4,5,6,7,8,9,10]
[1,2,3,4,5,6,7,8,9,10]
[1,2,3,4,5,6,7,8,9,10]
[8,16,24,32,40,48,56,64,72,80]
感谢您的时间和帮助!