4 ms·
What's wrong with OCaml's approach of just breaking out in imperative-style code whenever it suits you?
by AlexCoventry 5y ago
What's wrong with OCaml's approach of just breaking out in imperative-style code whenever it suits you?
- creata 5y agoImo, the advantage of "Haskell's approach" is that it's always obvious when you can and can't use imperative code, and the type system enforces it. I think this is important in many contexts, like STM[1] or Facebook's React[0]. But there are plenty of disadvantages: * it's a bit more verbose. * you can accidentally implement a weaker interface than the one you'd want, e.g. by only implementing Functor and not Traversable for your data structure. * the flip side of the benefits is that adding I/O to a previously pure function changes its interface. I don't know how it'd compare to OCaml's algebraic effects proposal, though. [0]: https://reactjs.org/docs/hooks-effect.html https://reactjs.org/docs/hooks-effect.html [1]: http://joeduffyblog.com/2010/01/03/a-brief-retrospective-on-transactional-memory/ http://joeduffyblog.com/2010/01/03/a-brief-retrospective-on-...
- lmm 5y agoYou lose the freedom to fearlessly refactor that's the main advantage of functional programming. If it's not clear which parts of the code can be reordered then you either just can't keep the code clean anywhere near as much, or you need much higher test coverage etc. to keep the same level of confidence when you do.