Some prerequisites: I am writing a general high-level compiler for low level. On the high-level side, he understands classes, methods, fields, calls to virtual methods, etc., And on the low-level side, he understands functions, structures, arrays, etc. Front-end translates compiled forms of languages such as Java (primary focus) and C # to my IR. An intermediate step reduces classes, methods, fields and virtual calls, etc. On function calls and structures. The back end splashes out C, LLVM IR (primary focus) or potentially others.
Currently, types (e.g. integers, floats, structures, classes, etc.) are (mostly) immutable. Classes allow you to add fields and methods because they do not change the type (i.e. class pointer). There is only one of any given type for each translation unit ("Module") - structures, pointers, arrays and other "derived" types. In other words, types have structural equivalence, such as LLVM, instead of name equivalence, such as C ++.
The problem I ran into is translating ClassType instances, which Java interfaces spill into StructType instances (with vtable pointer and all class fields) that the LLVM database understands, so that the system maintains a consistent state throughout the process. One of the difficulties is maintaining the equivalence of the structure - two different classes can be omitted into the same structure, and this must either be detected at the beginning of the lowering process, or adjusted after the lowering process.
This long explanation leads me to my question: can lazy evaluation languages such as Haskell offer a convenient solution? If so, how can this be translated into Java, perhaps using the Promise template?