Lazy lists

Here is the type of polymorphic lazy lists:

type 'a lazy_list =
  | Lnil
  | Lcons of 'a * 'a lazy_list Lazy.t;;

Analysis:

  • Lnil is a zero-ary constructor that represents the empty lazy list; and

  • Lcons is a binary constructor that, given

    • a value v and
    • a suspension that, when forced, yields a lazy list,

    constructs a lazy list that starts with v and whose tail is represented by the suspension and thus not computed yet.

[...]

Version

Created [28 Mar 2019]

Table Of Contents

Previous topic

Demand-driven computation

Next topic

Streams