Type checking instances
To expand instances, we want to expand them one by one, in a pipeline. To type check instances we can then do the following for each argument to an instance: for every new resource, we store its inferred type (the strongest type consistent with its use in that instance) in a map; for every resource already in the map, we check that its inferred type from the instance to expand is compatible with the type stored in the map, and then add the strongest of the two to the map. We then raise an error otherwise.