[MLton-user] eqtype and error msgs from MLton

Raymond Racine rracine@adelphia.net
Thu, 28 Oct 2004 22:55:46 -0400


signature OPAQ_T = 
sig
    type ot
    val mkOT: int -> ot
end

structure OpaqT:> OPAQ_T = 
struct
  type ot = int

  fun mkOT s = s
end

signature ADT =
sig
    type t

    val mkT: int * int -> t
end

structure Adt :> ADT = 
struct

  exception BadBoy

  datatype t = T1 of OpaqT.ot | T2 of int

  fun mkT (1,x) = T1 (OpaqT.mkOT x)
    | mkT (2,x) = T2 x
    | mkT _ = raise BadBoy
end

fun showTruth t = if t 
		  then print "Truth\n"
		  else print "False.\n"

fun test() = let val v11 = Adt.mkT(1,1)
		 val v12 = Adt.mkT(1,2)
		 val v13 = Adt.mkT(1,1)
	     in
		 showTruth(v11 = v12);
		 showTruth(v11 = v13)
	     end

val _ = test()

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.

I found this error msg a bit of a red herring.  Though the first error
msg was clear I needed an eqtype, I of course focused on why I was
getting this one.

  Variable type in structure disagrees with signature.
    variable: mkT
    structure: _ -> [t]
    signature: _ -> [unit]

Then after the first fix, a more helpful error msg would point out that
Adt.t is not of type equality specifically because OPaqT.ot was not.

Now that I've grokked the pattern its no big deal.  But a while back I
recall seeing a email requesting feedback on the clarity of compiler
error msgs.

Ray