I attempted to summarize the approaches we have available with data representation problem. I think that probably in the end, we may need to use a code generation solution rather than try to find a solution in terms of language constructs. The code generation would allow us to construct a type of tags, over which we may match efficiently, possibly using phantom types. I guess, it’s not too bad.
I wonder, if any ppx or other libraries exist that would allow me to generate type definitions (and also code) that extend upon existing variant types (and pattern-matches)? Basically, something along the lines
type _ tag =
| Int : [> `Int] t
| Float : [> `Float] t
module Item_params = struct
(* item params data ... *)
type _ tag =
[%extend: _ tag]
| Sprite : [> `Sprite]
| Sound : [> `Sound]
end
There’s no need for any type equality relationships between the instances inside the Item_params and outside, only creating a new instance of a type based upon template is sufficient.