An implementation of Algorithm W.
Use new type variable variant (Generic) instead of 'generic level' to represent generic variables.