Re:Functional programming is finally going mainstream
by zelphirkalt on Wednesday July 13, 2022 @11:45AM
(#32084300)
You are correct in general about FP. I am talking about introducing FP in an existing OOP program though. You might want to use existing parts, but they are usually all impure, with lots of side effects. Any function in which you use those existing parts will be impure as well, unless you resort to things like IO monad. However, that makes it more complicated to implement things. You are building another layer of protection from the existing code and its state mutations everywhere.
When you are programming in FP, you are describing the program from another POV - taking the IO monad as an example, it just constructs a “list” of steps that should be taken at a given point vs just listing the steps in the program itself.
In pure FP languages, immutability is enforced due to you describing a given state - it simply doesn’t make sense to change something there.