[MLton-devel] Strange behaviour with exceptions

Stephen Weeks MLton@mlton.org
Sat, 18 Oct 2003 09:43:12 -0700


> fun can f x = (f x; true) handle Interrupt => raise Interrupt | _  => false;

Interrupt is not a toplevel exception in the Standard Basis.  It is a
Moscow ML deviation to put it there.  So, this program is exactly as
if you had written

  fun can f x = (f x; true) handle zzz => raise zzz | _  => false;

Thus, the program will reraise whatever exception f raises, and the _
case is redundant.  The latest internal version of MLton even gives
you the required redundancy warning.

Warning: z.sml 1.34: handler has redundant rules
   rules: _ => false
   in: (f x ; true) handle (Interrupt) =>   ...  Interrupt) | (_) => false

> So I thought that MLton must think Interrupt is not an exception, and
> so be treating it as a catch-all pattern. 

Right.

> But if this is the case, then why doesn't it complain about raising
> Interrupt?

Because Interrupt is bound by the pattern, and is hence a valid
variable on the right hand side of the rule.

> There are plenty of workarounds. This seems like the most elegant:
...
> But I'd prefer not to have to change the HOL source any more than
> necessary. And I can't see why the original program doesn't work.

If you want the MLton toplevel to look more like Moscow ML, you can
prefix your program with

	exception Interrupt = SML90.Interrupt

Note that even SML90 has gone away in -basis 2002.  Although there's
no reason I can see why you couldn't prefix your program with

	exception Interrupt



-------------------------------------------------------
This SF.net email sponsored by: Enterprise Linux Forum Conference & Expo
The Event For Linux Datacenter Solutions & Strategies in The Enterprise 
Linux in the Boardroom; in the Front Office; & in the Server Room 
http://www.enterpriselinuxforum.com
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel