Get the latest tech news
Basic dependency injection in OCaml with objects
A simple way to encode dependency injection using the Reader monad and objects in OCaml (to work well with type inference).
In his article Why I chose OCaml as my primary language, my friend Xavier Van de Woestyne presents, in the section , two approaches to implementing dependency injection: one using and one using modules as first-class values. For my part, I find that dependency injection makes unit testing a program trivial, which I think is reason enough to care about it (For example, the time-tracker I use at work, Kohai, uses Emacs as its interface and the file system as its database. In OCaml, the richness of the object model (and its structural capabilities) is a real advantage for this kind of encoding, allowing a drastic reduction of the boilerplate needed to manage multiple sets of dependencies.
Or read this on Hacker News