I am implementing an API client, and the API is very connected, so if you have two types, responses,
A contains a method for accessing its associated,
B contains a function to access its associated
A, and there are numerous other types involved which have a similar relationship.
B also have many fields in common, such as
date or whatever.
At first I thought a bunch of mutually recursive records was an option but I’m not sure what to do about accessing all the overlapping fields. Recursive modules would be nice as they allow namespacing each type, but the amount of typing involved in recursive modules feels a lot.
The way I’m trying to represent things is the responses are records and they do not contain an instance of each other, but the URL to query the other then I have functions to take the input and return the other. I would like the methods namespaced with the type, though, otherwise I could do something like below:
module Type: module A : sig type t end module B : sig type t end end module Op : sig module A : sig val get_b : Type.A.t -> Type.B.t end module B : sig val get_a : Type.B.t -> Type.A.t end end
Any other suggestions for the best way to approach this?