Context:
I’m trying to extend ocaml-torch library with some custom functions. The torch library builds bindings to libtorch and provides wrapper types in OCaml
Torch_core.Wrapper.Tensor.t is an alias of the ctype - Torch_core.Wrapper_generated.C.Tensor.t
Problem:
I would like to extend this module with some additional C bindings.
My module: Qtensor.mli. This is basically Tensor module but with one additional function
I’m generating the bindings for this additional function using Ctypes.
include module type of struct include Torch_core.Wrapper.Tensor end
module C : module type of Qtorch_bindings.C(Qtorch_generated) with type t := Torch_core.Wrapper_generated.C.Tensor.t
val tensor_to_int : t -> int
I’m unable to prove to the compiler that Torch_core.Wrapper_generated.C.Tensor.t is an alias of the Torch_core.Wrapper.Tensor.t in my new module
include Torch_core.Wrapper.Tensor
module type QC = module type of Qtorch_bindings.C(Qtorch_generated)
module C : QC with type t := Torch_core.Wrapper_generated.C.Tensor.t = Qtorch_bindings.C(Qtorch_generated)
let tensor_to_int t =
C.tensor_to_int t (* fails *)
Error:
rror: The implementation external/qtorch/core/qtensor.ml
does not match the interface external/qtorch/core/.qtorch.objs/byte/qtorch__Qtensor.cmi:
Values do not match:
val tensor_to_int : Torch_core.Wrapper_generated.C.Tensor.t -> int
is not included in
val tensor_to_int : t -> int
The type Torch_core.Wrapper_generated.C.Tensor.t -> int
is not compatible with the type t -> int
Type
Torch_core.Wrapper_generated.C.Tensor.t =
(unit, [ `C ]) Qtorch_generated.CI.pointer
is not compatible with type t
File "external/qtorch/core/qtensor.mli", line 5, characters 0-28:
Expected declaration
File "external/qtorch/core/qtensor.ml", line 26, characters 4-17:
Actual declaration