Hello,
I want to define a functor that defines a type t and functions on that type such that t is a subtype of a polymorphic variant type.
For instance, if we have a type
type t_full = [ `A of int | `B of string | `C of int*int | `D ]
I want to be able to define a functor similar to this
module type T_SUBTYPE =
sig
type t_full = [ `A of int | `B of string | `C of int*int | `D ]
type t = [< t_full ] (* Not accepted by OCaml *)
end
module OpsOnTSubtype (T: T_SUBTYPE) =
struct
type t = T.t
let f : [> t ] -> int =
function
| `A i -> i
| `B s -> String.length s
| `C (l,r) -> l + r
| `D -> 0
end
However, I don’t know how to define the module signature T_SUBTYPE.
Is this possible in OCaml ?
Thanks in advance,
Frédéric