[MLton-user] eqtype and error msgs from MLton
Thu, 28 Oct 2004 22:55:46 -0400
signature OPAQ_T =
val mkOT: int -> ot
structure OpaqT:> OPAQ_T =
type ot = int
fun mkOT s = s
signature ADT =
val mkT: int * int -> t
structure Adt :> ADT =
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
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)
showTruth(v11 = v12);
showTruth(v11 = v13)
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.
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