package zlist

  1. Overview
  2. Docs
Lazy lists for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

zlist-0.1.2.tbz
sha256=216eb03fc9ba6b0034b26e4ccc20cb2d23e95ee44b1e365ee0b5dbd163d5113f
md5=bdade429cbb5150067407dccb353525e

Description

zlist consists of the definition of a lazy list type and a number of useful functions for manipulating and constructing lazy lists.

Published: 05 Jan 2017

README

zlist: Lazy lists for OCaml

v0.1.2

zlist consists of the definition of a lazy list type and a number of useful functions for manipulating and constructing lazy lists.

About

Development is hosted at GitLab.

API documentation can be found online.

Inspiration

This implementation is heavily inspired by "Functional Programming in Scala", by Chiusano and Bjarnason (2014).

Installing

The easiest way to install zlist is through the opam repository:

$ opam install zlist

Building

Alternatively, you can build and install zlist from its sources. This is easiest with the topkg-care package installed.

First, pin the sources using opam:

$ opam pin add zlist <TOP-LEVEL SOURCE DIRECTORY>

then build the package:

$ topkg build

After the package is built, zlist's test suite is run by invoking

$ topkg test

Lazy lists

The type of a lazy list is

type 'a t =
  | Nil
  | Cons of 'a Lazy.t * 'a t Lazy.t

That is, unlike a normal list, both the head and tail of a cons cell is lazily-evaluated. This lazy structure allows us to generate infinite lists and to apply arbitrary transformations to the list without constructing new instances in memory.

Examples

Assume this following code has been evaluated in the OCaml top-level:

#require "zlist" ;;
open Zlist ;;

We can generate an infinite list of even integers:

let evens = Lazy_list.(enum_from 0 |> map (fun x -> 2 * x)) ;;

and observe the first 10:

Lazy_list.(take 10 evens |> to_list) ;;

- : int list = [0; 2; 4; 6; 8; 10; 12; 14; 16; 18]

The fibonacci numbers can be generated via Lazy_list.unfold:

let fibs = Lazy_list.unfold (0, 1) (fun (a, b) -> Some ((b, a + b), a)) ;;
fibs |> Lazy_list.(take 10 |> to_list) ;;

- : int list = [0; 1; 1; 2; 3; 5; 8; 13; 21; 34]

License

zlist is copyright 2016 by Jesse Haber-Kucharsky.

zlist is released under the terms of the Apache license, version 2.0. See /LICENSE for more information.

Dependencies (4)

  1. topkg build & >= "0.7.8"
  2. ocamlfind build & >= "1.6.2"
  3. ocamlbuild build & >= "0.9.2"
  4. ocaml

Dev Dependencies (1)

  1. alcotest with-test & >= "0.7.2"

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.