[Haskell-cafe] Why instances can't be hidden (was: non-total operator precedence order)

Brian Hulley brianh at metamilk.com
Sat Nov 11 11:19:59 EST 2006


Benjamin Franksen wrote:
> Henning Thielemann wrote:
>> On Fri, 10 Nov 2006, Benjamin Franksen wrote:
>>> Although one could view this as a bug in the offending module it
>>> makes me somewhat uneasy that one additional import can have such a
>>> drastic effect on the code in a module /even if you don't use
>>> anything from that module/.
>>
>> It's the same as with instance declarations, isn't it? I don't want
>> to defend the problems arising with todays anonymous instance
>> declarations,
>
> Right. However, with instances I can imagine solutions that avoid
> naming them, that is, I could imagine to write something like
>
>  select instance C T1 T2 ... Tn from module M
>
> or
>
>  import M hiding (instance C T1 T2 ... Tn, ....)
>
> Such a feature could prove extremely useful in practice.
>
> Disclaimer: I am almost sure that there is something I have
> overlooked that makes such a simple solution impossible, otherwise it
> would have been proposed and implemented long ago...

I think the reason you can't do this kind of thing is that within any set of 
modules that is compiled at the same time, anywhere in any of these modules, 
if you have a type T that's an instance of class C, then all occurrences of 
C T must refer to the exact same instance declaration or else things would 
get totally messed up when/if the compiler did whole program optimization.
In other words, the instances are actually properties of the type(s) 
themselves so allowing different modules to "see" different implementations 
of the instances would break the conceptual merging of modules (modulo 
renaming) that occurs at compile time.

Regards, Brian.
-- 
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.

http://www.metamilk.com 



More information about the Haskell-Cafe mailing list