Back to Contents

Loading a Program from a File

Now that we are building larger functions, we might like to store them between sessions, rather than typing them in every time. For example, compose a file like this in a text editor:

image

Save the file in same directory (folder) as you enter OCaml from, under the name lists.ml. We can then tell OCaml to use the contents of that file like this:

image

It is exactly the same as typing it in manually – the functions length and append will now be available for use. Errors and warnings will be reported as usual. Note that the #use command is not part of the OCaml language for expressions – it is just a command we are giving to OCaml.