when am creating choice using either function,whenever error has been occurs means then they returns values to the left side of the either,which is terminating the complete template itself that is not proceeding further for other scenario execution,how to do both same functionality in daml instead of Either.
1 Answers
If execution doesn't proceed further, then the error is not handled. Moreover, a Left
can't be simply ignored. Consider this DAML function:
steps : Bool -> Either Int Bool
steps q = do
a <- if q then Left 1 else Right "foobar"
return $ a == "foobar"
a
is a Text
, which is only present if the Either
is Right
. So if the Either
is Left
, execution cannot proceed to the last line, because there is nothing to assign to a
.
It wouldn't do to change this behavior just because you might get an Either Text Text
. So in this case, too, the variable will only be bound if it's Right
.
It also wouldn't do to change behavior just because you removed the variable. For example,
steps2 : Bool -> Either Int Bool
steps2 q = do
if q then Left 1 else Right "foobar"
return q
If the semantics suddenly "just kept going" because you eliminated an unused variable binding, that would be incredibly inconsistent and confusing. So it stops right there on Left
, just as if a <-
was still there.
The thing is, this is not just about Either
; this holds for all "error-reporting-style" actions, because they are all characterized by "I don't have a value to bind to your variable", so execution can never proceed further in any do
, even if you use an "alternative" to Either
.
You must handle the error right there if you want execution to proceed; in other words, if you have a Left
, you have to come up with a Right
if you want it to keep going, and that has equivalence in any action that features error-reporting, because they all have missing a
values that you must come up with. Indeed, the meaning of error for all is "I can't come up with a value for your a <-
or whatever else you're doing".

- 175
- 7