▲ | rybosome 4 days ago | |
Thanks for the detailed reply, that’s very cool! This looks great, very usable way to do DI. Do you use Haskell professionally? If so, is this sort of DI style common? | ||
▲ | abathologist 4 days ago | parent | next [-] | |
I am not a Haskell expert, nor an expert in effect systems, but, AFAIU, what mrkeen has provided is an analogous pattern in Haskell -- where effects are represented via the free monad with an interpreter -- and not an account of what is described in the article. In OCaml we can (and do) also manage effects via monadic style. However, we don't have ad hoc polymorphism (e.g., no typeclasses), so that aspect of the dependency injection must go thru the more verbose (but more explicit, and IMO, easier to reason about) route of parametric modules. The point in the article is that effect handlers allow direct-style code with custom effects, which enable a kind of "dependency injection" which actually looks and feels much more like just specifying different contexts within which to run the same program. If you are very used to doing everything in Haskell's monadic style, you may not really notice the difference, until you try to compose the handlers. Here is an example I've put together to show what the author is talking about in practice: https://gist.github.com/shonfeder/a87d7d92626be06d17d2e795c6... | ||
▲ | mrkeen 3 days ago | parent | prev [-] | |
No idea how common it is. It's never been my main work language but I've been using it at work for prototyping/scripting/automation/analysis etc for at least ten years now. It looks like what I've done is most similar to https://www.parsonsmatt.org/2018/03/22/three_layer_haskell_c... And I think this was the post that proposed tagless-final over free-monads: https://markkarpov.com/post/free-monad-considered-harmful.ht... |