On Mon, Jun 24, 2013 at 1:19 PM, Eric Niebler
On 13-06-24 11:53 AM, Pierre Talbot wrote:
This misses what is, IMO, the most important use case of Haskell's Either monad: automatic error propagation. This would be more useful if there were a way to call a function such that if any of the function's arguments were an Either-in-error, the function would immediately return the error.
I implemented something like this. Check out substitution_failure and try_call starting here:
https://github.com/ericniebler/proto-0x/blob/master/boost/proto/v5/utility.h...
In the Expected proposal, there are some methods related to this idea.
<snip various do-syntax derivatives>
If we really care about adding a do syntax EDSL, why not make it general
purpose like Haskell's version so that it can work with any monad and
compose better with other things?
either
I honestly think that if Either goes into Boost, we shouldn't consider it as a value or error structure at all. Expected (will) do the job.
Seems a bit excessive to me to have both. If we get Expected, then Either is unnecessary -- it's just one template alias away from variant. I don't consider the syntactic niceties of "left" and "right" to be compelling, and if folks want it, we can provide left and right free functions for 2-arg variants. But IMO automatic error propagation is the *only* thing that can make this proposal compelling.
I personally find myself using std::pair frequently even though it is also just one template alias away from std::tuple. I still think there's a case for exposing these commonly-useful simple building blocks. Incidentally, the std::pair monad is also interesting. David