[MLton] A Possible "Bug"?

Matthew Fluet matthew.fluet at gmail.com
Fri Dec 18 09:02:21 PST 2009


On Fri, Dec 18, 2009 at 9:15 AM, Henry Cejtin
<henry.cejtin at sbcglobal.net> wrote:
> I  would  say  that  MLton is correct and SML/NJ is wrong.

Agreed, with the caveat noted below.

> The point is
> that the left hand side of the binding in
>    val [[x]] = []
> is a non-exhaustive pattern and the right hand side does not match any of
> the  cases.  (The type is correct though.)  Hence evaluating this should
> result in the Bind exception being raised.
>
> At least in v110.67 of SML/NJ, that is what happens.
>
> Perhaps you are being confused by the fact that  the  exception  raising
> happens  at  evaluation  time.   In  MLton,  that  is  when  you run the
> executable, but in SML/NJ, it is when you enter the  expression  to  the
> read-eval-print loop.

There is a subtle difference in SML/NJ's behavior:

Standard ML of New Jersey v110.71 [built: Thu Oct  1 09:13:22 2009]
- val [[x]] = [];

unexpected exception (bug?) in SML/NJ: Bind [nonexhaustive binding failure]
  raised at: stdIn:1.5-1.15
             ../compiler/MiscUtil/print/ppobj.sml:396.20
             ../compiler/TopLevel/interact/evalloop.sml:44.55

- val SOME x = NONE;

unexpected exception (bug?) in SML/NJ: Bind [nonexhaustive binding failure]
  raised at: stdIn:1.5-1.18
             ../compiler/MiscUtil/print/ppobj.sml:396.20
             ../compiler/TopLevel/interact/evalloop.sml:44.55

- val NONE = SOME 1;

uncaught exception Bind [nonexhaustive binding failure]
  raised at: stdIn:1.5-1.18

The last is what I would expect to see in all cases.  The others seem
to be a case where the the REPL isn't expecting a Bind exception; it
seem to be related to patterns that should be binding variables (i.e.,
they are entered into the static environment), but then are not bound
due to the pattern match failure (i.e, they are not entered into the
dynamic environment).

> Note,  if  SML/NJ  did  not  issue a warning about the binding not being
> exhaustive then that would be a bug in their code.

Except that the Defn states: "However, this warning should not be
given when the binding is a component of a top-level declaration...."
MLton gives pattern-match warnings in all cases.


> ----- Original Message ----
> From: Baojian Hua <huabj at mail.ustc.edu.cn>
> To: mlton <mlton at mlton.org>
> Sent: Fri, December 18, 2009 4:02:57 AM
> Subject: [MLton] A Possible "Bug"?
>
> ...
>
> However, I happened to run this code:
> val [[x]] = [];
>
> MLton reports a warning message, but smlnj-110.71 reports
> an error (compiler bug?). I'd like to ask here that which
> behaves correctly?
>
> _______________________________________________
> MLton mailing list
> MLton at mlton.org
> http://mlton.org/mailman/listinfo/mlton



More information about the MLton mailing list