且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

哈斯克尔名单冻结

更新时间:2022-10-15 09:19:39

You know that the list is monotonically increasing, but Haskell does not. Use takeWhile, instead of a list comprehension, so that list1 can stop being evaluated once you find a value greater than 4.

> list1 = [1..]
> list2 = takeWhile (<= 4) list1
> print list2
[1,2,3,4]