JavaScript interface
JavaScript features are accessible via JavaScript structure.
ES modules can be imported with _esImport declaration: Importing ECMAScript Modules.
ES export
To produce an ES module, use --lib compiler option and define a variable or structure named export.
For example,
val export = <some value>;
will compile to
export default <some value>;
and
structure export = struct
val foo = "string"
val bar = 42
val fun' = "fun" (* SML keywords can be escaped by suffixing with a prime *)
end
will compile to:
const foo = "string";
const bar = 42;
const fun = "fun";
export { foo, bar, fun };
Note on CPS mode: You cannot call certain functions including print at top-level, because they are “async”.
In future, this limitation may be lifted by using top-level await.
Internal representation
Warning: The internal representation of data types may change in the future. Do not rely on it!
unit(empty record)undefined.boolJavaScript’s boolean;
trueorfalse.int54-bit signed integer, as a subset of Number. Overflows are always checked.
word32-bit unsigned integer, as a subset of Number. The sign of zero must be positive.
real64-bit floating-point number (JavaScript’s native Number).
char8-bit unsigned integer. The sign of zero must be positive.
stringUint8Array. Must not be modified.Char16.char16-bit unsigned integer. The sign of zero must be positive.
String16.string16-bit string (JavaScript’s native String).
Int54.int54-bit signed integer, as a subset of Number (close to “safe integer”). The range is \([-2^{53},2^{53}-1]\). The sign of zero may be negative. Overflows are always checked.
Int64.intBigInt. Overflows are always checked.
IntInf.intBigInt.
Word64.wordBigInt.
'a vectorArray. Must not be modified.
'a arrayArray.
JavaScript.valueAny JavaScript value, including
undefinedornull.- Non-empty record
{ "0": <#1 of the record>, "foo": <#foo of the record> }