Sequencing and observing Except #
Core and Batteries state how <$> acts on Except.ok and Except.error, but not >>=, and
nothing about Except.toOption, which forgets which error occurred. These equations let simp
evaluate do blocks over Except and compare computations up to the error they raise.
For a list of computations run from left to right, List.mapM and List.filterMapM succeed
exactly when every step does, and then return the results of the steps. Batteries characterizes
the successful results of List.mapM by List.Forall₂ (List.mapM_eq_ok_iff_forall₂); the
observations here say the same through Except.toOption, in a form that is stable under
permutations and filters of the list.
A specification x.Spec P E says that x succeeds with a result satisfying P or fails with an
error satisfying E. Specifications of the steps of a do block compose by Except.Spec.bind,
so a proof that a program only fails in a given way needs no case for each step that can fail.
Main results #
Except.ok_bind,Except.error_bind:>>=on a result and on an error.Except.bind_eq_ok: a sequenced computation succeeds when both steps do.Except.toOption_bind,Except.toOption_map: observing success commutes with sequencing.Except.toOption_eq_some_iff: an observed success is a success.Except.toOption_mapM,Except.toOption_filterMapM: the observation of a list of computations.Except.mapM_eq_ok_map,Except.toOption_mapM_congr:List.mapMof succeeding steps, and of steps with the same observations.Except.Spec,Except.Spec.bind: a computation succeeds with a result satisfyingPor fails with an error satisfyingE, and such specifications compose along>>=.Except.Spec.mapM,Except.Spec.filterMapM: the results of a successful list of computations come from steps meeting their specifications.
Continuing with Except.ok returns the computation: the right unit law in the normal form
of Except.pure_eq_ok.
Lists of computations #
List.filterMapM succeeds exactly when every step succeeds, and then keeps the present
results.
Postconditions #
x.Spec P E: x succeeds with a result satisfying P, or fails with an error satisfying
E. Specifications of the steps of a do block compose by Except.Spec.bind.
Instances For
A sequenced computation meets Q and E when its first step meets P and E, and the rest
meets Q and E from every result of the first step satisfying P.
Every result of a successful List.filterMapM comes from a step whose specification it
meets.