How do I derive a type class for different type parameters?