3 ms·
IO isn’t (typically) functional, and neither is the IO monad. But like reference types in Clojure, it’s how you express “the world is stateful, my program usual
by eyelidlessness 6y ago
IO isn’t (typically) functional, and neither is the IO monad. But like reference types in Clojure, it’s how you express “the world is stateful, my program usually is not, but for this exceptional case my program interfaces with the world.” I don’t think React hooks are a good way to signal that, but they’re one of the ways people who prefer FP in real world use do it. I think Redux type solutions are a better signal in some cases, and the rare stateful class component has is better in others. I hope hooks don’t take over the React ecosystem, but if they do I’ll be looking for other solutions similar to earlier React with regular functions and stateful escape hatches.
- flowerlad 6y agoIO isn't functional and that's the reason FP languages such as Haskell have a system for dealing with functions that have side-effects, that neatly separates the part of the program that is pure and the part of the program that is impure (and does all the dirty work like updating the screen). Impure parts of the program is fenced off from the pure parts. Pure functions cannot call impure functions. The important part here is keeping portions of your code that has side-effects separate — and minimizing the amount of such code. If code that has side-effects is spread all over your program then you are not really using functional style. More on that here: https://medium.com/weekly-webtips/dysfunctional-programming-in-javascript-cae5c085a76e https://medium.com/weekly-webtips/dysfunctional-programming-...
- eyelidlessness 6y agoThat was exactly my point!
- mssundaram 6y agoDo you mean that you prefer the lifecycle hooks like componentDidMount etc.? If so I'd be very curious to hear more about why
- valenterry 6y ago> IO isn’t (typically) functional, and neither is the IO monad "(pure) functional" is an attribute of expressions, not of concepts. Hence saying "the IO monad is not functional" does not make much sense. a function that returns an `IO` type, which when executed performs a side-effect, is indeed pure functional though. Hence, react hooks are not pure functional, by the common definition of functional programming.