12345678910111213141516171819202122232425includePpx_deriving_runtimelet(>>=)xf=matchxwithOkx->fx|(Error_)asx->xlet(>|=)xf=x>>=funx->Ok(fx)letrecmap_bindfaccxs=matchxswith|x::xs->(* equivalent to [f x >>= fun x -> map_bind f (x :: acc) xs],
but do not use [(>>=)] to keep [map_bind] tail-recursive
under js-of-ocaml *)(matchfxwith|((Error_)aserr)->err|Okx->map_bindf(x::acc)xs)|[]->Ok(List.revacc)type'aerror_or=('a,string)result(** [safe_map f l] returns the same value as [List.map f l], but
computes it tail-recursively so that large list lengths don't
cause a stack overflow *)letsafe_mapfl=List.rev(List.rev_mapfl)