Avoiding extra matching with extensible GADTs

Agreed.

Once again, agreed.

Sure. Especially considering that these types already exist, and the issue that I have come across is more about tagging the types rather than organization of the game data itself.

This is what I am trying to conceptually avoid as much as possible. Ideally, all the types related to sprites should be editable through sprite-related modules, and the generic modules should be aloof about their presence.

There’s a certain difference between freely tagging the data, like e.g. `Sprite of Game_sprite.t and defining a type case like type t += Sprite of Game_sprite.t. The use of polymorphic variants is in principle acceptable. However, my problem is not entirely solved, since I still need to find a scheme to tag the data, and thus to translate from `Tag into `Tag of data_type within a function that does the tagging. The attempted use of GADTs that allow simple type-mapping seemed like a nice trick, but perhaps I need to consider an entirely different approach.

The solution would probably involve partial matching through the use of GADTs and phantom labels. For me it’s more of a last-resort solution, since it breaks conceptual modularity (by relying on the centralized all-encompassing data-type that contains all relevant tags), and it seems that we’re missing some opportunity that may already have been in existence.

The conceptual problem for me with this approach is that it creates a landmine of sort. Someone could deliberately feed an input to my program that would “crash” it – which is the effect of assert false statement. I seek to avoid that. In the future, I may be the one inadvertently triggering that assert false case. It’s a fate that I wish to avoid as a software developer responsible for the codebase.

I also feel that this breaks abstraction, where we have slighly different modi (pl. of modus) of encoding type values in the different parts of the game, and it is appropriate for them to use their own data-types, albeit very similar. The aim I try to achieve is to eliminate code duplication involved in handling the cases that are common to all these types.