2 Building Applications

2.6 Delivering applications with MLWorks

MLWorks allows you to produce executables and image files from ML applications. This process is known as delivery.

An image file contains an image of a particular function inside MLWorks. The file is read by the MLWorks runtime system, which recreates and evaluates the function it contains. In the useful case this function has side-effects, which are the output of the application being delivered. An executable file is similar, but includes the runtime system code as well, so it is free-standing.

Applications can be delivered using the function MLWorks.Deliver.deliver. This function takes three arguments:

To be specific, suppose you have defined the following function. It may have been defined in a file that was compiled and loaded, or in a file that was called with use, or by typing directly in the listener.

fun hello () = print "Hello, world.\n";

The print function is available at top-level in MLWorks, so you do not need to read any library code into MLWorks, nor require any libraries, to make this example work. For a delivery example that does use other libraries, see Section 3.5 on page 49, which delivers a simple program that uses the Standard ML Basis library for I/O.

By invoking MLWorks.Deliver.deliver from a listener, you can now deliver the function hello as an image file:

MLWorks> MLWorks.Deliver.deliver ("hello.img", hello, false);

or as an executable file:

MLWorks> MLWorks.Deliver.deliver ("hello", hello, true);

The image file is invoked using the mlimage script, which is part of the MLWorks distribution:

> mlimage hello.img
Hello, world.
>

The executable file hello, considering what it does, may seem quite large. However, this is because it must contain a copy of the MLWorks runtime. This is a constant overhead (somewhat under 300 KB), so is less significant for larger programs. By contrast, the overhead for an image file is only about 6 KB.


MLWorks User Guide (UNIX version 1.0) - 3 DEC 1996

Generated with Harlequin WebMaker