[MLton] Is there any "Unsafe.cast" in mlton?

Stephen Weeks MLton@mlton.org
Thu, 20 May 2004 18:00:08 -0700


> I need a function like Unsafe.cast in SML/NJ. Is there such a
> function in Mlton?

No.

> I found from mlton.org that the Unsafe structure in Mlton is a
> subset of that in SML/NJ. Does it mean there is no cast function in
> Mlton? If so, is there any solution to achieve the same
> functionality as Unsafe.cast?

To work correctly, Unsafe.cast assumes that the representations of the
types between which it is casting are the same.  This, of course,
could vary from compiler to compiler.  And, because MLton is very
aggressive in its optimization, could vary quite a bit based on small
program changes.

So, unless the types are some basic ones whose representation is
hardwired into MLton (like, say, casting from int vector to word
vector), there isn't much to be done.  If you'll send the code, or a
summary of what it's trying to do, we can try to help you figure out
what's possible.