Primavera is a dependency injection library for OCaml inspired by the proposal in the articles "Basic dependency injection with objects". The name Primavera is a bitter nod to Spring, which gave me grey hairs when I was developing in the JVM world.
To make our software easy to test (and potentially to vary its runtime or interpretation), OCaml provides several tools likes:
- Modules, using Functors or Module-dependent functions and first-class modules
- Effects
- Many others (objects, records, labelled argument etc).
Although these approaches all offer advantages—such as continuity checking for effects and the ability to introduce types for modules—these advantages often capture aspects of very advanced programming. And sometimes, we would like a simpler approach, while still preserving type inference and tracking dependencies within the type system.
Primavera combines OCaml's object model with a Reader Monad to allow certain operations to be abstracted while still being tracked within the type system. See the teletype example for a very brief usage example.
The library also provides functors for building wrappers around
parameterized types such as Result, Lwt, or Option, and allows
you to describe traversable structures.