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
Inner-traversal signatures
These signatures form the inner body of the On_monad functor in the main signatures. They all have names ending with _on_monad, and assume the existence of a monad M.
While they aren't interesting on their own, they do contain (in slightly abstract form) the specific functions needed to build, and provided on building, traversable containers.
The generic signatures
As with Mappable, we define some signatures for traversable structures in an arity-generic way, then specialise them for arity-0 and arity-1 types.
S1_on_monad extends Generic_on_monad with functionality that only works on arity-1 containers.
Basic signatures
Any traversable type can be turned into a Core container, using the monadic fold to implement all container functionality. The unified signature of a container with monadic traversals is S0 (arity 0) or S1 (arity 1).
To satisfy these signatures for new types, implement Basic0 or Basic1, and use the corresponding MakeN functor.
For types that are _already_ Core containers, or types where custom implementation of the Core signature are desired, implement Basic0_container or Basic1_container, and use the MakeN_container functors.
S1 is a generic interface for arity-1 traversable containers. It also includes the extensions from Mappable.
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.