[MLton-devel] intInf -- was obscure SML/NJ misfeature.

Allyn Dimock dimock@cs.uml.edu
Tue, 29 Jul 2003 17:57:52 -0400


Matthew,

Back in June I wrote to you for help figuting out a bug in trying to
port some SML/NJ code to SML'97 with 2002 library for use with MLton.
 
[dimock@localhost compiler]$ mlton elab-trans-mlton.cm
FLINT/trans/matchcomp.sml:245.6-245.15 Error: unify: type constructors not equal
    t1: int32
    t2: intInf
 compilation aborted: type check reported errors

(the error message that I sent in, from mlton-20030312-1, was int vs. intInf).

You pointed out that SML/NJ uses an odd version of IntInf in its Util
library rather than the IntInf defined in the standard basis, and
suggested that out-of-order entries in the .cm file might cause such a
type error.

I finally got back to looking at this.  The bug is actually the result
of an interesting "gotcha" buried down in some code stolen from the
SML/NJ compiler:

  sig
    val int32  : IntInf.int -> Int32.int
    ...
  end

  struct
    val two_31 = IntInf.pow(two, 31)
    val neg_two_31 = IntInf.~ two_31
    fun int32 i = IntInf.toLarge(chkIntRange (neg_two_31, two_31) i)
    ...
  end

SML/NJ makes the assumption that Int32 == LargeInt
MLton states in its documentation that IntInf == LargeInt (which
matches the requirement in the Standard Basis documentation).

    fun int32 i = Int32.fromLarge(IntInf.toLarge(chkIntRange (neg_two_31, two_31) i))
fixes the problem.

You can (almost) add that to SML/NJ's list of misfeatures.
The basis library documentation says "If an implementation provides
the IntInf structure, then LargeInt must be the same structure as
IntInf (viewed through a thinning INTEGER signature)."
SML/NJ can only make the excuse that it doesn't really provide IntInf.

-- Allyn



-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel