+ module T2(Wrapped : Monad.S2) = struct
+ module Trans = struct
+ include Monad.MakeT2(struct
+ module Wrapped = Wrapped
+ type ('x,'a) m = ('x,'a option) Wrapped.m
+ type ('x,'a) result = ('x,'a option) Wrapped.result
+ type ('x,'a) result_exn = ('x,'a) Wrapped.result_exn
+ (* code repetition, ugh *)
+ let elevate w = Wrapped.bind w (fun a -> Wrapped.unit (Some a))
+ let bind u f = Wrapped.bind u (fun t -> match t with
+ | Some a -> f a
+ | None -> Wrapped.unit None)
+ let run u = Wrapped.run u
+ let run_exn u =
+ let w = Wrapped.bind u (fun t -> match t with
+ | Some a -> Wrapped.unit a
+ | None -> failwith "no value")
+ in Wrapped.run_exn w
+ end)
+ let zero () = Wrapped.unit None
+ let plus u v = Wrapped.bind u (fun t -> match t with | None -> v | _ -> u)
+ end
+ include Trans
+ include (Monad.MakeCatch2(Trans) : Monad.PLUS2 with type ('x,'a) m := ('x,'a) m)
+ end