I can’t wrap my head around the differences between sequence and LazyList. They’re both lazy and potentially infinite. While seq<'T> is IEnumerable<'T> from .NET framework, LazyList is included in F# PowerPack. In practice, I encounter sequences much more often than LazyLists.
What are their differences in terms of performance, usage, readability, etc? What are reasons for such a bad reputation of LazyList compared to that of seq?
LazyListcomputes each element only once regardless of how many times the list is traversed. In this way, it’s closer to a sequence returned fromSeq.cache(rather than a typical sequence). But, other than caching,LazyListbehaves exactly like a list: it uses a list structure under the hood and supports pattern matching. So you might say: useLazyListinstead ofseqwhen you need list semantics and caching (in addition to laziness).Regarding both being infinite,
seq‘s memory usage is constant whileLazyList‘s is linear.These docs may be worth a read.