I end up with this but I do not know if this is the best solution. withHdf5PathP loc (H5Or l r) = ContT $ \cont -> (runContT (withHdf5PathP loc l) cont) `catchAll` const (runContT (withHdf5PathP loc r) cont)