3 ms·
I'm sure it has its problem domains, but does FP work well when interfacing with non-FP languages? Is that where monads / imperative language wrappers come in?
by LockAndLol 6y ago
I'm sure it has its problem domains, but does FP work well when interfacing with non-FP languages? Is that where monads / imperative language wrappers come in?
- ratww 6y agoI did a lot of stuff with F# and C# together. Calling FP from imperative is nothing special. Calling imperative from FP only requires external purity in the imperative functions (if you want FP to remain pure, of course). Not different from using pure functions in an imperative language. Monads... they're just a way of remaining pure (meaning immutable) but still doing imperative-ish stuff. You don't need monads to make software: both pure-FP and imperative languages can be Turing-complete, so you can do it all. For doing IO you can just use an imperative shell [1], that "calls" the main function of your pure-FP program (aka: a runtime). Monads for IO make it easier to communicate with this "imperative shell" while still remaining pure. It communicates with it by requiring you to return an IO object all the way to your main function. But Monads can also be used for other things that don't need IO, like "internal mutable state", "maybe monad" or even for simulating an exception system. Those don't require you returning anything. Monads are nothing special for real... but you have to use to understand them, since most explanations just make it harder to understand, so I won't attempt one. [1] https://www.destroyallsoftware.com/screencasts/catalog/functional-core-imperative-shell https://www.destroyallsoftware.com/screencasts/catalog/funct...