Implement a complete type inference system for dag patterns, based on the