
2 Building Applications
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:
unit -> unit. This is the function to be evaluated when the image is loaded
true for an executable file, false for an image file
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.

Generated with Harlequin WebMaker