Hi there,

I'm having a problem with type classes.

I have a class called PrettyPrintable,

For data type:

data Generic a = ......

I need to provide instance of Generic a for type class PrettyPrintable.

The parameter type a could be either PrettyPrintable or Show.

If I write the following, it won't compile:

instance Show a => PrettyPrintable (Generic a) where
  ......

instance PrettyPrintable a => PrettyPrintable (Generic a) where
  ...


How do I achieve this?

Another alternative that I think may work is if I can say "all Show a will
be PrettyPrintable a in terms of this implementation". But it seems that
the following code won't compile either:

instance Show a => PrettyPrintable a where
  ......


Am I doing the design totally wrong? Or there is actually some clever
scheme in Haskell that can do this elegantly?

Thanks.

Ben.




This message is intended only for the addressee and may contain information
that is confidential or privileged. Unauthorized use is strictly prohibited
and may be unlawful. If you are not the intended recipient, or the person
responsible for delivering to the intended recipient, you should not read,
copy, disclose or otherwise use this message, except for the purpose of
delivery to the addressee. If you have received this email in error, please
delete and advise us immediately.


_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to