Monads and branches
The current way to use exceptions to deal with failed branches does not work when using a state monad, unless the Branch_fail
exception is raised in pure code. Is the exception is raised in monadic code (and for the state monad, that means waiting for the state to proceed with evaluation), then the first branch is always returned. If it was supposed to fail, the exception will be raised outside the try with
.
I'm afraid we have to find a way to make the branch aware of the monad, to replace
try
(function s -> raise Branch_failed)
with Branch_failed ->
try
(function s -> ((),s))
with Branch_failed -> raise Branch_failed
with
function s ->
try
raise Branch_failed
with Branch_failed ->
try
((),s)
with Branch_failed -> raise Branch_failed