Ocaml combining signatures
Suppose I have two signatures, Ordered, and Field
module type ORDERED = sig
type t
type comparison = LT | EQ | GT
val cmp : t -> t -> comparison
end
module type FIELD = sig
type t
val (+) : t -> t -> t
val ( * ) : t -> t -> t
val inv : t -> t
val neg : t -> t
val zero : t
val one : t
end
And I want to make a functor that takes two Ordered Fields and produces another Ordered Field (say operations are applied component-wise and we use dictionary order for comparison). How would I specify that the "input modules" satisfy two signatures simultaneously?
Here is some strawman syntax for what I want to do:
module NaivePair = functor (Left : ORDERED & FIELD) (Right : ORDERED & FIELD) ->
struct
type t = Left.t * Right.t
(* definitions *)
end
It might be the case that there's an elegant way to take a "union" of signatures (but not an anonymous union), or create a wrapper module around concrete ORDERED and FIELD implementations that just happen to share a type t. I am curious what the idiomatic OCaml way to do what I am trying to achieve is.