Re: [MLton] MLton deviation (or else PolyML is wrong)

Matthew Fluet <[email protected]> Sun, 2 Feb 2014 11:48:44 -0500
Newsgroups gmane.comp.lang.ml.mlton.devel
Message-ID <CAMrhFL53T70rnyW22Q24SKLrHKRauXCmsVuPZNuAFCmWdBMQPg@mail.gmail.com>
On Sun, Feb 2, 2014 at 9:12 AM, Yannick <[email protected]> wrote:
> I've encountered a case where MLton accepts an SML program while PolyML
> reject it. At line 332 and line 335 of the attached SML program, PolyML
> complains type `Word8Vector.vector` is not compatible with type
> `VectorSlice.vector`, and MLton don't.
>
> PolyML says:
>
>     Can't unify bytes = Word8Array.vector (*Created from opaque signature*)
>     with 'a vector (*In Basis*) (Different type constructors)
>
> I'm not sure of which is wrong and which is right.

One could argue that they are both right: The Basis Library
specification dictates when two types must be equal, but doesn't
dictate when two types must be unequal.  The rationale for the
MONO_{ARRAY,VECTOR}{,_SLICE} structures is that some compilers may
choose to implement a monomorphic array or vector differently than a
polymorphic array or vector.  MLton, on the other hand, doesn't
implement monomorphic arrays and vectors any differently than
polymorphic arrays and vectors.  Hence, MLton can reveal the type
equality between "Word8Vector.vector" and "Word8.word vector".

On the other hand, you could argue that for portability reasons, MLton
shouldn't expose this type equality.  And, indeed, MLton doesn't do so
for the other monomorphic arrays/vectors: "VectorSlice.vector o
Int8VectorSlice.slice" does not type-check.  I can't precisely recall
why the Word8 type equalities are propagated.

In any case, there is a simple solution in your application: use the
"structure Word8VectorSlice : MONO_VECTOR_SLICE" module, which
provides slice operations on a monomorphic vector.

------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable 
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk