2007/10/2, skaller <skaller@users.sourceforge.net>:
On Tue, 2007-10-02 at 20:02 +0200, kirillkh wrote:
> Replying to a private mail from Brian:

> (* I couldn't figure out, how to declare a polymorphic exception
> properly *)
> exception Done of 'a

That's easy -- you can't: even if you could, how could
you possibly use it?

This compiles fine:

type t = { field : 'a. 'a }
exception Done of t

but 'field' is useless. This is not at all the same as

        let f (x:'a) (g:'a -> int) =
        match g x with
        | 0 -> ..
        | ..

because *inside* the function, 'a is not a type variable,
and the code is not polymorphic, it is simply a sole
unknown type, sometimes said to be monomorphised.

The problem with exceptions is that they're not captured,
so they cannot be polymorphic. Exceptions SUCK because
their context is not delimited -- you can throw all the way
out of the mainline .. :)

[This happens to me regularly and it can takes days to figure
out what is Not_found ..]

Is there a way to instantiate an exception with a value of unspecified type and then do explicit casting on catch?

Is it a deficiency in the language? I suppose OCaml could support polymorphic exceptions, if they were checked, like in Java, and appeared in function signatures in a similar way to parameters and return values.