Now I can show off its behavior by trying to fetch one or an other value from the stateful map (see this post for details), it fails becaue the map only has values associated to "a" and "b":
The interest here is the programming style: we either do one part of the expression or the other. But more importantly that we have defined the OR operator to capture errors as a state. So running (run test16 (testState1,) ) the above test will produce:
let (&&&) m1 m2 = SM (fun ((s,err) as sr) ->
The code is much more simple than the OR because we do not need to take the state appart as we depend on each of the monadic arguments to do that for us.
As we want to get "a" AND get "b" we can write are test code as following:
This puts the focus on the fact that this definition of the AND operator is returning a tuplet of the two successfuly return values. Now again we can see it manage errors:
When run will produce the expected initial "transactional" state with the error state: