package travesty

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

Monadic traversal.

Traversable provides signatures and functors for containers and data structures that can be 'traversed': mapped across with a monadic side-effect. It resembles the Haskell Traversable typeclass, but with two differences:

  • We currently define traversability in terms of monads, not applicative functors (this might change in the future, but monads are generally more well-understood and well-supported in the OCaml/Core ecosystem);
  • as a result, the main 'traverse' function is called map_m.

Signatures

Traversable_intf contains the signatures for Traversable.

include module type of Traversable_intf

Signatures for monadic traversal.

The generic signature

As with Mappable, we define the signature of traversable structures in an arity-generic way, then specialise it for arity-0 and arity-1 types.

module type Generic = sig ... end

Generic describes monadic traversal on either an arity-0 or arity-1 type.

Basic signatures

module type S0 = sig ... end

S0 is the signature of a monadic traversal over arity-0 types.

module type S1 = sig ... end

S1 is the signature of a monadic traversal over arity-1 types.

Building containers from traversable types

Input signatures

module type Basic_container0 = sig ... end

Basic_container0 is the signature that traversable containers of arity 0 must implement.

module type Basic_container1 = sig ... end

Basic_container1 is the signature that traversable containers of arity 1 must implement.

Helper signatures

module type Generic_on_monad = sig ... end

Generic_on_monad extends Generic to contain various derived operators; we use it to derive the signatures of the various On_monad modules.

module type On_monad1 = sig ... end

On_monad1 extends Generic_on_monad with functionality that only works on arity-1 containers.

module type Generic_container = sig ... end

Generic_container is a generic interface for traversable containers, used to build Container0 (arity-0) and Container1 (arity-1).

Signatures for traversable containers

module type S0_container = sig ... end

S0_container is a generic interface for arity-0 traversable containers.

module type S1_container = sig ... end

S1_container is a generic interface for arity-1 traversable containers. It also includes the extensions from Mappable.

Making containers

Monadic traversal is sufficient to define fold, and, therefore, all of the key functionality for a Core-style container. As such, we expose functors for building traversable Core-style containers.

module Make_container0 (I : Basic_container0) : S0_container with module Elt = I.Elt and type t := I.t

Make_container0 makes a S0_container from a Basic_container0.

module Make_container1 (I : Basic_container1) : S1_container with type 'a t := 'a I.t

Make_container1 makes a S1_container from a Basic_container1.

Chaining together traversables

module Chain0 (Outer : S0_container) (Inner : S0_container with type t := Outer.Elt.t) : S0_container with module Elt = Inner.Elt and type t := Outer.t

Chain0 chains two S0_container instances together, traversing each element of the outer instance with the inner instance.

Helper functions

module Helpers (M : Base.Monad.S) : sig ... end

Utility functions for building traversals.

OCaml

Innovation. Community. Security.