Why don't we have an "`import` what you use" commandment in Haskell?
I think PVP’s solution isn’t pragmatic in the first place. Imagine you are reviewing a PR on package C and are trying to ensure that C has direct dependencies on all of the packages that provide instances used by C.
I think it’s also unreasonable in the C++ case, but C++ is simpler, so let’s look at that first. For each identifier referenced in new code in the PR, you need to find its provenance, and then check that all of those headers are explicitly listed in the file. And you should also go through to see which identifiers are no longer referenced in the code and see if any of those headers can be removed. Not impossible, but far from pragmatic, IMO.
Then the Haskell case makes it worse, by removing the identifiers. You now have to find the types of all the new identifiers used in the code, mentally do type resolution to determine the set of instances, and then find those particular instances (where some of the instances might be more general than the types you resolved), and add “empty” imports for any modules containing those instances that aren’t already imported. And again, you should also go through and do the reverse to determine which ones should be removed based on no-longer-used instances.
The removal is actually even more difficult, because you actually would have to go through the entire module not just the identifiers you’ve removed references to, since just removing import Only.For.The.Instances () might still compile, but you’re now using some of those instances via transitive import, creating the situation you’re trying to avoid.
Discussion in the ATmosphere