Type Classes and Instance Chains: A Relational Approach