How do I create dynamic exceptions

Exceptions, again... The docs for Control.Exception say (for Dynamic exceptions): "When using dynamic exceptions it is advisable to define a new datatype to use for your exception type, to avoid possible clashes with dynamic exceptions used in other libraries." So I went with that and created a datatype for my exceptions:
data MyException = MkExc Int String
... but now it seems I have to install this as an instance of Typeable, and I don't see how to do that.
instance Typeable MyException where typeOf ? = ?
***************************************************************** The information in this email and in any attachments is confidential and intended solely for the attention and use of the named addressee(s). This information may be subject to legal professional or other privilege or may otherwise be protected by work product immunity or other legal rules. It must not be disclosed to any person without our authority. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are not authorised to and must not disclose, copy, distribute, or retain this message or any part of it. *****************************************************************

On Tue, 22 Jul 2003 12:51:24 +0100
"Bayley, Alistair"
Exceptions, again...
The docs for Control.Exception say (for Dynamic exceptions): "When using dynamic exceptions it is advisable to define a new datatype to use for your exception type, to avoid possible clashes with dynamic exceptions used in other libraries."
So I went with that and created a datatype for my exceptions:
data MyException = MkExc Int String
... but now it seems I have to install this as an instance of Typeable, and I don't see how to do that.
instance Typeable MyException where typeOf ? = ?
The documentation for Data.Dynamic is pretty clear for this and I believe with GHC6 you can derive Typeable. {-# NOINLINE myExceptionTyCon #-} -- the documentation suggests a fully qualified name myExceptionTyCon = mkTyCon "MyException" instance Typeable MyException where typeOf _ = mkAppTy myExceptionTyCon []

data MyException = MkExc Int String
... but now it seems I have to install this as an instance of Typeable, and I don't see how to do that.
instance Typeable MyException where typeOf ? = ?
import Data.Dynamic myExceptionTc = mkTyCon "MyException" instance Typeable MyExceptionBasicSpec where typeOf _ = mkAppTy myExceptionTc [] The above should work, but I wonder when it is possible to simply derive Typeable? Cheers Christian
participants (3)
-
Bayley, Alistair
-
Christian Maeder
-
Derek Elkins