Idea: Standard OCaml runtime type representation

I didn’t know about that one. I didn’t fully grok some of the structural bits there but it looks quite interesting. It would have been nice to have examples of generic functions written with it though.

However one thing I feel is missing from that one is the ability to attach heterogeneous dictionaries to nodes of the type representation. Either on each node directly or as a special node tagging another one with the dictionary (the latter being likely much more inconvenient for processors and users).

I think this is quite important to have that as it allows libraries acting on the type representation to declares typed keys that users can use to enrich their representation to guide the behaviour of the generic functions provided by the libraries.

For example an UI or HTML form library would declare a key for storing human readable labels (or keys to them for i18n), a serialization library would provide a key to tag data that should be ignored for serialization (and a default value to use on deserialization in but in this case I don’t think that could be typed), etc. The hypothetic Stdlib.Type.Repr module could even define a few standard keys.

LexiFi seems to have that albeit in the typical stringly fashion of unityped languages. That’s what happens when you work outside the rich ML language :–)

3 Likes