I was playing with the typer with some RPC description (a binding for libgrpc and ocaml-protoc-plugin) in OCaml 3.13.1:
module type Message = sig
type t
end
type 'a feature_availability = ([< `Yes | `No ] as 'a)
(** Used to indicate that a service as some feature or not *)
module type Rpc = sig
module Request : Message
type client_streaming
end
type ('req,'cs) service =
(module Rpc with type Request.t = 'req and
type client_streaming = 'cs feature_availability)
let make_service_functions :
type req cs . (req,([< `Yes | `No ] as cs)) service -> _ =
fun r ->
let module R = (val r) in
R.Request.from_proto, R.Response.to_proto
I got the typing error:
File "ocaml-protoc-plugin/src/ocaml_protoc_plugin/service.ml", line 37, characters 43-45:
37 | type req cs . (req,([< `Yes | `No ] as cs)) servic
^^
Error: Syntax error
I couldn’t get it to work with polymorphic variants, but here is a version that seems to work, with GADTs:
module type Message = sig
type t
end
type yes = Yes_t
type no = Not_t
type 'a feature_availability =
| Yes : yes feature_availability
| No : no feature_availability
(** Used to indicate that a service as some feature or not *)
module type Rpc = sig
module Request : Message
type client_streaming
end
type ('req,'cs) service =
(module Rpc with type Request.t = 'req and
type client_streaming = 'cs feature_availability)
let make_service_functions :
type req cs. (req, cs feature_availability) service -> _ =
fun r ->
let module R = (val r) in
R.Request.from_proto, R.Response.to_proto
(this code doesn’t type-check, but for more obvious reasons: from_proto is missing from Request, and Response is missing)
File "ocaml-protoc-plugin/src/ocaml_protoc_plugin/service.ml", line 61, characters 19-26:
61 | let module R = (val r) in
^^^^^^^
Error: The type of this packed module contains variables:
('req, [< `No | `Yes ]) service