package travesty

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

Signatures and functors for containers and data structures that can be mapped across with a monadic side-effect.

Modules based on this pattern 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

For input and output module signatures for this module's functors, see Traversable_types.

Making traversable containers

Monadic traversal is sufficient to define fold, and, therefore, all of the key functionality for a Base-style container. As such, our signatures and functors subsume those for building containers.

New containers

module Make0 (I : Traversable_types.Basic0) : Traversable_types.S0 with module Elt = I.Elt and type t = I.t

Make makes an S0 from a Basic0.

module Make1 (I : Traversable_types.Basic1) : Traversable_types.S1 with type 'a t = 'a I.t

Make makes an S1 from a Basic1.

Extending existing containers with monadic traversals

Make0_container makes an S0 from a Basic0_container.

Make1_container makes an S1 from a Basic1_container.

Combining and modifying traversable containers

Chaining

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

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

Fixing the element type

module Fix_elt (I : Traversable_types.S1) (Elt : Base.Equal.S) : Traversable_types.S0 with module Elt = Elt and type t = Elt.t I.t

Fix_elt (I) (Elt) demotes an S1 S to an S0 by fixing the element type to that mentioned in Elt.

Helper functions and functors

module Const (T : Base.T) (Elt : Base.Equal.S) : Traversable_types.S0 with module Elt = Elt and type t = T.t

Const constructs a S0 over container T and arbitrary element type Elt that, when traversed, makes no calls to the supplied function and returns the container unchanged.

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

Utility functions for building traversals.

OCaml

Innovation. Community. Security.