and told the reader that I would provide a XML free variant soon. From the API docs I think that it should be possible to construct the menu with API calls without XML use, so the reader would have the opportunity to see which variant he likes better. Unfortunately I never managed to get the XML free version working. Before I try again, has someone already managed it? In Nim, C, Python, or maybe in another language? Or do we at least have an idea how to do the conversion? I think in last winter I was already on a good way, but I have not saved the files and can not remember details.
I’ve converted your example to work with SML bindings (example.sml) and then produced a version that doesn’t use XML (example.sml). Although these examples are for GTK 3, they don’t use deprecated features of GTK 3 so the differences from GTK 4 shouldn’t matter here.
Notably, the version without GtkBuilder defines a recursive data type for menus and a function to build a menu from this in MenuBuilder.sml. In any language with suitably expressive sum types, this technique can be applied to create ad hoc types that enable a declarative description of an interface. In this example, instead of the XML representation, we get a declarative SML representation.