Importing and Exporting Instance Declarations

Ben Rudiak-Gould Benjamin.Rudiak-Gould at
Sat Nov 4 13:45:56 EST 2006

Bas van Dijk wrote:
> Can anybody explain or point me to previous discussions about why it isn't 
> allowed to import and export instance declarations?

With the exception of instance declarations, the module system deals only 
with names, not scope. Importing a module just gives new names to things 
that were (in principle) already in scope.

Instance declarations are an unfortunate special case, because (like type 
signatures and fixity declarations) they don't introduce any identifiers, 
but (unlike those declarations) they aren't tied to identifiers introduced 
in the same module. As a result, their very existence destroys the purity of 
import declarations. I think that this problem could have been prevented by 
requiring that every instance declaration mention in its head a type or 
class that was declared in the same module, but I doubt that would go over 
well -- people already complain enough about the fact that you can't use 
"deriving" across modules.

So explicit import/export of instance declarations would not be a very 
natural extension. Even if a semantics could be worked out, it would 
presumably be necessary to preserve the current rules against overlapping 
instances, meaning that you couldn't do things like hide the Prelude 
definition of Num Int and define your own locally.

-- Ben

More information about the Haskell-prime mailing list