Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
refactoring: avoid long tuples in typing/typeclass.ml by using records with named fields #7927
Original bug ID: 7927
typing/typeclass.ml uses long records with many components, only some of which are accessed each time. Example of not-so-nice-looking code includes:
Using records with named fields would improve the readability of this part of the codebase. Different tuples of different length are used in different places of the code, so three things may be useful:
(Note: one could think of using object types as extensible records here, but we are trying not to use objects directly in the compiler for bootstrapping reasons, so staying with less-flexible record types is the better idea.)
Hi! I started on this issue by figuring out which functions need refactoring first. Then I put those functions and their large tuples in a table below to see overlaps. We can see that
Edit: btw, going through HACKING.adoc was very helpful.
Answering 3, the benefits will be:
Going for the low-hanging fruit, that is the four functions you identified to use the exact same shape, and converting them into a shallow record (instead of trying to reorganize via nesting), sounds like a good first step to me.
For how to use the object-oriented parts of the language, see for example the Real World OCaml chapter on objects. For the implementation of the type system,
For the theory behind it, it would be the academic article Objective ML: An effective object-oriented extension to ML (journal).
I don't think any of these contain enough explanations to clarify the implementation, though. In any case, the nice thing with refactoring is that we don't really need to understand finely the code we are working with :-)