4 ms·
Oh, there's many problems with suggested approach. - Callback-oriented programming is its own deep can of worms. What do you want to inline where? In case of
by m1el 9y ago
Oh, there's many problems with suggested approach.
- Callback-oriented programming is its own deep can of worms. What do you want to inline where? In case of leftMap, it's easy for a compiler to inline flatMap, because it's small. What if you're providing a lambda to a huge function? What about variable captures? Really, we've been there with JavaScript.
- It will either incur a yuuge runtime overhead or will require a new calling convention.
- What if you want to transform your data multiple times? Will you use nested lambdas?
IMO, using sum types is the best solution to this problem. Sum types are not "weird special type", they don't require "weird calling convention", C++ is weird for NOT supporting them.
- AstralStorm 9y agoWe have also been there in a variety of functional languages and no problems there. What runtime overhead, a function call? Pointer dereference? Even template magic on the error monad type won't save you from that one. The problem is shifted to the dereference. There you get either to handle an exception or error code, or explicitly check the state of the object. Nested lambdas do work reasonably well. But remember, were generally talking about error handling, not a callback that is supposed to run big transforms.