I am trying to determine how to manage types and conversions between types within a compiler that I am writing. The compiler is being written in C#.
There are a number of different kinds of types.
- Classes (read only / not mutable)
- Mutable Types (Which contain another type. Think the opposite of C++ const.)
- Generic Types (With constraints referring to types)
- etc
The problem I am trying to solve is, given two types, how can I determine whether one can be converted to the other. (eg. Allow a mutable type to be assigned to the read only version of the type)
My first thought was to use a virtual method and a visitor. However, since types can depend on others (e.g. A mutable type is a wrapper referring to another type.), this can cause the number of cases that need to be handled to balloon. I am looking for a design that keeps this to a minimum.