Is there any way to pass a type into a function?
The purpose would be to push marshalling code into a send function, rather than obstructing the main code.
I’m currently doing something like:
type 'a typ = Int: int typ | Bool : bool typ
send_typed : 'a -> 'a typ -> unit
= fun v typ ->
let s = match typ with
| Int -> Int.to_string v
| Bool -> Bool.to_string v
in send s
However if I could match on the type explicitly that would be easier.
(The reason that this is required is due to using protocol buffers, which requires a bytes type and sending via something which only takes strings… hence: v |> Protobuf.Encoder.encode_exn protobuf_from_v |> Bytes.to_string
…)