Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Monads or something like them are vital to be able to recover imperative programming in a functional context. If functional programming means programming with functions (in the mathematical sense) then it means expression-oriented languages/styles, and how you express conventional (procedural) programming idioms in those is a key part of having a functional programming language that you can actually use.


What's wrong with OCaml's approach of just breaking out in imperative-style code whenever it suits you?


Imo, 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

[1]: http://joeduffyblog.com/2010/01/03/a-brief-retrospective-on-...


You 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: