[MLton] MLton.Exn.setTopLevelHandler
Matthew Fluet
fluet at tti-c.org
Wed Jun 13 07:24:13 PDT 2007
Vesa Karvonen wrote:
> AFAICT, MLton doesn't currently expose the functionality to set the
> top-level handler to a user-defined function.
I believe that is correct.
> Is there some reason why functionality
> equivalent to Primitive.TopLevel.setHandler is not exposed?
I don't see why not. I don't think it was clear why it would be useful.
Generally, wrapping a 'main' function with a "handle _ => ..." usually
accomplishes the same thing.
> Below is a patch that exposes setHandler as
> MLton.Exn.setTopLevelHandler. It wraps the handler with a function
> that exits. The wrapping is not absolutely necessary, but probably
> makes it easier to use. Any objections to applying this patch (with
> or without the wrapping)?
I think the patch looks fine. There is one oddity --
MLton.Exn.topLevelHandler is equivalent to the default top-level
handler, rather than the dynamically installed top-level handler. I
don't think that is bad, but just a curiosity. We might rename
MLton.Exn.topLevelHandler to something that doesn't suggest that it is
the 'getter' for MLton.Exn.setTopLevelHandler.
I think it does make sense to wrap the installed handler with the
additional "handle _ => ..."; if we allow arbitrary user code to run as
the top-level handle, it may itself raise an exception. And MLton
doesn't behave particularly well when an exception is raised with no
handler in scope.
More information about the MLton
mailing list