I am building two libraries in OCaml which contain the same variant type. The detail of the variant is not too important, other than that it is really large, and it would be annoying to manually write conversion functions for it. (It's actually the bfd_architecture enumeration converted from C using ocamlidl).
I'm now writing a program using the two libraries. In particular, I'm calling A.f which returns a value of A.variant_type, and I need to use that value in a call to B.g, which takes a value of B.variant_type as an input.
Is there any way to tell OCaml that A.variant_type and B.variant_type are really the same type, and thus it's okay to convert a value from one to the other? The libraries are independent, so they should not reference each other. Right now I'm using Obj.magic to do the conversion, but this is a hack.
OCaml distinguishes between structural equality and physical equality (essentially equality of the address of an object). = is structural equality and == is physical equality.
The |> operator represents reverse function application. It sounds complicated but it just means you can put the function (and maybe a few extra parameters) after the value you want to apply it to.
I believe there is no clean way unless these libraries have some common dependency which defines this type (i.e. the same module referenced from both libraries at build time).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With