On Sunday, February 20, 2000 4:13 PM, Fergus Henderson 
[SMTP:[EMAIL PROTECTED]] wrote:
>
> Well, you can always defined a type using Tree which _is_ an instance of 
Ord:
>
>       newtype OrdTree = MkOrdTree Tree
>       instance Ord OrdTree where ...
>
> So I don't see this as a disaster.
>

The example of when you might want to hide an instance (of Read, to prevent 
forgery) is persuasive.

However, how would you prevent the client following the advice given above 
of using a newtype declaration to redefine your type, making that an 
instance of Read, and thereby forging values of your type?

I imagine that the answer is that this cannot be done if the type is 
exported without its constructors**, which would be necessary anyway to 
prevent back-door accesses to your type. But then your suggested workaround 
for my problem is not available.

Actually the situation is worse than I thought. If your module defines a 
type T to be an instance of Ord, but fails to export that instance, then a) 
If I can't see the body code of your module, I probably (depending in the 
interface information) won't even know until link time that I can't declare 
this instance. b)  I will be unable to declare an instance, not just of 
Ord, but also of all the many subclasses of Ord.

** The Haskell report appears to be silent on this, although it seems 
obvious that an instance cannot be declared or derived if the type's 
constructors are not visible. Is it also true that this would also preclude 
declaring a Newtype? Simon?

--brian

Reply via email to