package travesty

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Zipper implements the 'list zipper' data structure.

A list zipper contains two lists: a 'right list', which represents a sequence of data to be processed; and a 'left list', which collects the sequence of data already processed in reverse order. At any point, the first element in the right list---the 'cursor'---represents the item currently being processed.

The usual use case of a zipper is to 'slide' across the right list, moving elements onto the left list one by one, and then 'rewind' the left list back onto the right for further processing.

These versions of the list zipper contains a few extensions. First, many operations can be parametrised by a monad---this will usually be an error monad like Or_error, but can be anything else (like a state transformer).

Second, items in zippers constructed using Make_marked can be marked, attaching a tag to them; later on, if the item still exists in the zipper, the zipper can be rewound back to the mark using recall.

For documentation on the signatures of both zippers and the parameters of the functors below, see also Zipper_intf.

include module type of Zipper_intf
module type S_non_monadic = sig ... end

S_non_monadic contains the core operations of a zipper, without any parametrisation over a particular failure monad.

module type S_monadic = sig ... end

S_monadic contains the core operations of a zipper, parametrised over a particular failure monad.

module type S = sig ... end

S contains S_non_monadic; a functor for generating S_monadic over a custom monad; and specialisations of it over common monads.

type ('mark, 'a, 'acc, 'final) fold_outcome = [
  1. | `Stop of 'final
    (*

    Stop folding, immediately return

    *)
  2. | `Drop of 'acc
    (*

    Drop the cursor and continue

    *)
  3. | `Swap of 'a * 'acc
    (*

    Replace cursor with a new value

    *)
  4. | `Mark of 'mark * 'a * 'acc
    (*

    Replace, and mark, the cursor

    *)
]

The type of instructions returned by functions used with fold_until_m and fold_until.

module type S_marked_non_monadic = sig ... end

S_marked_non_monadic extends S_non_monadic to add functions for manipulating marks.

module type S_marked_monadic = sig ... end

S_marked_monadic extends S_monadic to add functions for manipulating marks.

module type S_marked = sig ... end

S_marked extends S to add functions for manipulating marks.

module type Basic_mark = sig ... end

Basic_mark is the interface that mark types must implement.

Plain zippers

module Plain : S

Plain is a basic list zipper, without specialised functionality.

Marked zippers

module Make_marked (Mark : Basic_mark) : S_marked with type mark := Mark.t

Make_marked makes a marked zipper from a Basic_mark.

module Int_mark_zipper : S_marked with type mark := Base.int

Int_mark_zipper is a marked zipper whose marks are integers.