[MLton-user] eqtype and error msgs from MLton

Stephen Weeks MLton-user@mlton.org
Fri, 29 Oct 2004 18:34:26 -0700


Hi Ray.  Thanks for the suggested improvement.

> The above program (properly) fails to compile.
> The first fix is "eqtype t" in the ADT sig.
> Then second fix is "eqtype ot" in OPAQ_T.

When I feed your original program to MLton, I get the following:

Error: z.sml 41.18.
  Function applied to incorrect argument.
    expects: [<equality>] * [<equality>]
    but got: [<non-equality>] * [<non-equality>]
    in: = (v11, v12)
Error: z.sml 42.18.
  Function applied to incorrect argument.
    expects: [<equality>] * [<equality>]
    but got: [<non-equality>] * [<non-equality>]
    in: = (v11, v13)

Those errors clearly point to Adt.t not being an eqtype.  After
changing type t in ADT to eqtype, I get the following:

Error: z.sml 21.18.
  Type t admits equality in signature but not in structure.
Error: z.sml 21.18.
  Variable type in structure disagrees with signature.
    variable: mkT
    structure: _ -> [t]
    signature: _ -> [unit]

These errors must be what you are referring to in your message.

> I found this error msg a bit of a red herring.  Though the first error
> msg was clear I needed an eqtype
...
> a more helpful error msg would point out that Adt.t is not of type
> equality specifically because OPaqT.ot was not.

I agree that the "admits equality signature" message could be clearer.
I have extended that kind of message to include the reason why the
type does not admit equality.

> I of course focused on why I was getting this one.
> 
>   Variable type in structure disagrees with signature.
>     variable: mkT
>     structure: _ -> [t]
>     signature: _ -> [unit]

This is indeed a spurious error.  I tweaked the type checker to be a
little more careful to avoid the problem.

With both of those changes, the output is now:

Error: z.sml 21.18.
  Type t admits equality in signature but not in structure.
    not equality: T1 of OpaqT.ot

with no further errors displayed.

Thanks again.  Spurious errors are often hard to track down and fix,
and we are interested in user reports to help catch them.