Explanation
Welcome to the Explanation section of the provider documentation. This section covers how provider works and its design principles.
Synopsis
Provider is an OCaml library for creating Traits and Signatures to build upon some functionality needed by a library without committing to an actual implementation for it, until runtime.
In essence, it provides a way to handle dynamic dispatch, where the target of a function call is not known until runtime. This is particularly useful in situations where there are many ways to provide a certain functionality, and the choice of provider is determined by the user at runtime.
Rationale
The rationale for this design is detailed in the Eio documentation.
Motivation
The Provider library started as an experimental project that extracted a pattern featured in the Eio project. The goal was to make this pattern reusable in other projects.
We then went on to use Provider as building block for the parametrization of the Vcs project.
However, after some time, we switched Vcs to a design using OCaml objects directly, and didn't make use of Provider after all (see this vcs pr).
Implementation
At its core, a Provider is a pair consisting of an internal state and a virtual-table of first-class modules operating on that state. This allows dynamic dispatch, but for example doesn't include open recursion or inheritance in its execution model. This design offers an interesting balance between object-oriented and modular programming.
Experimental Status
Please note that this library is highly experimental. The original goal was to to gain experience and feedback regarding whether this pattern could have applications outside of the scope of Eio. However, we're unsure about the project's future at this point.