How to map the inputs and outputs of a list of functions in a module?

So let’s say I have a module A with the following signature

module A : sig
type t
val foo : t -> input -> output
val bar : t -> input -> output
end

Also, I have an arbitrary monad module M, that has the following type type 'a t.

Now I would like to create a module B such that it maps the signatures of the functions in the following way:

module B: sig
type t
val foo : t M.t-> input -> output M.t
val bar : t M.t -> input -> output M.t
end

Is there a nice way to do this in OCaml? I don’t think you can use regular functors to do this because they require you to know the name of each function.

This is often done with a lift function

Also, OCaml let you use higher-order functions in modules:

module B = struct

(* type t *)

let lift f t input = (* do the lift *)

let foo = lift A.foo
let bar = lift A.bar

end

Not within the type system. First of all, OCaml doesn’t support the kind of type-level compuation you’d need to turn 'a -> 'b -> 'c into 'a 't -> 'b -> 'c 't. Then you’d need some functor that could iterate over its argument’s vals to apply this function, which I don’t think is possible in any language with ML-like modules.

You could probably write a ppx to generate all the code automatically, but IMO that’s more trouble than it’s worth and it’s better to just do it manually as @Juloo suggested above.

It’s probably not central to your problem: there is no way to create a value of A.t because t is abstract and none of the functions in A are creating such a value.