本文介绍了什么是有用或有趣的无限生成器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无限生成器有哪些巧妙的用法?我看过很多看似琐碎的示例,例如列出所有偶数" ,但我认为必须存在其他一些对现实世界场景更适用的示例.具体示例(使用支持生成器的任何语言)表示赞赏!

What are some clever uses for infinite generators? I've seen lots of seemingly trivial examples like "list all even numbers", but I assume there must be others that have more applicability to real-world scenarios. Concrete examples (in any language that support generators) appreciated!

我将给出一个简单的示例作为答案.

I'll give a trivial sample as an answer.

推荐答案

查看 http上的Haskell代码: //rosettacode.org/wiki/Hamming_numbers#Haskell ;会以一种创造性的方式使用惰性列表(有点类似于生成器)来列出所有汉明数字.

Look at the Haskell code on http://rosettacode.org/wiki/Hamming_numbers#Haskell; that uses lazy lists (which are somewhat like generators) in a creative way to list all Hamming numbers.

这篇关于什么是有用或有趣的无限生成器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 10:26