3 ms·
Using `Reader` is not dependency injection, it's dependency passing. It also has the downside of polluting all your function signatures and it exposes all the i
by zak_mc_kracken 12y ago
Using `Reader` is not dependency injection, it's dependency passing. It also has the downside of polluting all your function signatures and it exposes all the internal dependencies of a function to all its callers.
With dependency injection, you lose referential transparency but you gain a much cleaner and more encapsulated approach.
- tel 12y agoYou can pretty easily extend this with `mtl` in Haskell genericInjected :: MonadReader Handle m => m () If you use lenses you can express an even nicer pattern genericInjected :: HasHandle Database m => m () Perhaps the king here is ML's functors module ( Dbh : DatabaseHandle ) = struct ... end In all cases this isn't much more than "dependency passing", but there is clearly more "injectability" and encapsulation available. Ultimately it all comes down to the kind of typed interface you want to expose.