DEV Community

Discussion on: Why Functional Programmers Avoid Exceptions

Collapse
 
macsikora profile image
Pragmatic Maciej • Edited

Promise is composable but also does eagerly side effects and if we define function as something which is referencialy transparent then Promise is not. It return depends from the "state of the world" or just depends from time. And it makes it procedure more than a function, procedure which returns some value to the caller.
Things which return value are composable but without monads doing composition with values wrapped by Either would look like your Go example where every function would check if we have left or right.

And such Either Monad allows for composition positive path totally not thinking that there is any Either and possible error.

When we look on this though we see that it is exactly simulation of procedural exception which allows code to work in positive path and just goto catch for errors. Even exactly that was one of reasons Monads in Haskell were such a thing. They allowed for pure functional composition which could do the same staff like procedural code.