"binary" "bytecode" "compiler" "executable" "interpreter" "shebang" "source code" "toplevel" "virtual machine" Syntax: ocamlopt .ml -o OCaml is a flexible language in a number of ways. One in particular makes it quite suitable for rapid prototyping, portable deployment, and high performance application development. Other, more popular languages tend to have a single implementation that uses only a single mode of parsing and execution. OCaml appears to include, in a single distribution, every popular mode of parsing and execution. OCaml "source code" is the text in an OCaml program before it is prepared to be run as an application. This is what you write when you're programming. If you do not already understand the concept of source code, you may find some of the concepts in these tutorials difficult to understand, though I have endeavored to make them accessible to beginners. OCaml source code files are traditionally saved in a file with a name that follows the name.ml convention, using '.ml' as the file extension. A number of things can be done to prepare these files to be used as an executable program. A "compiler" is a program that parses source code and compiles, or translates, it into a file that is not 'human readable' but is, instead, meant to be read by the machine or a program running on the machine. There are compilers that are used to translate code between languages, such as compiling a high-level "scripting" language to C so that it can then be compiled to native "machine code". The "binary" compiler is probably the best known. This allows the programmer to compile to so-called 'native' machine code, like the .exe files familiar to many Windows users. This renders very fast, high-performance "executable" binary files similar to those produced by the C programming language. In fact, many benchmarks and real-world anecdotal evidence indicates that OCaml binaries are nearly as fast as binaries compiled from C, and are typically faster than those compiled from C++. This makes OCaml one of the best languages available for high performance application development. To compile a binary executable from your '.ml' file, you use the ocamlopt command at the command line, specify the source file, and optionally specify the output file using the '-o' argument. Typically, the source file and output file are intended to have the same name with the exception that the source file usually ends in '.ml' and the executable either has no filename extension (on unices, typically) or a '.exe' extension (on Windows). If the '-o' option is not used, the executable binary will be named 'a.out' by default (mostly for historical/legacy reasons). Compiling a source code file 'program.ml' to a binary executable 'program' would look something like this: ocamlopt program.ml -o program OCaml can also be used with a "bytecode" compiler and "virtual machine", similar to the way Java programs are used. This can provide for greater portability, because the same bytecode compiled file will run on any system architecture and operating system for which there is an OCaml virtual machine, whereas native binaries only run on the OS and architecture for which they were compiled. To get a binary executable to run on another, different system, you have to compile it specifically for that system, whereas all you need to run the bytecode compiled executable is the virtual machine. Compiling to bytecode is accomplished in much the same way as compiling to a binary executable as described above. The only difference you will usually encounter in command syntax is the name of the compilation command itself: ocamlc program.ml -o program There is also an OCaml "interpreter". This is a program that runs OCaml source code without requiring it to be compiled at all before execution. This provides some definite benefits for rapid development, as new code can be run and tested while you are working on it without requiring any compilation. It is also portable similarly to bytecode, because it runs anywhere there is an OCaml interpreter just as bytecode runs anywhere there is an OCaml virtual machine. On Unix-like operating systems such as FreeBSD, Linux, OpenSolaris, and even (to some extent) MacOS X, the file can be given execution permissions (this process should be known to almost all users of unices, particularly free unices) and have a "shebang" line that tells the system where to find the interpreter. On Windows, you would probably need to set system preferences so that the operating system recognizes the '.ml' file extension and associates it with the OCaml interpreter. On most unices (the term I, and others, use as the plural form of 'unix' with a lower-case letter, to refer to noncommercial Unix-like operating systems), the shebang line should look like this: #!/usr/bin/ocamlrun ocaml Finally, there is the OCaml "toplevel", which is an interactive execution environment, similar under the hood to the interpreter, superficially similar to a command shell (like the command line interface of DOS). It runs OCaml code the same way a command shell runs commands, and .ml files executed by the interpreter is to the OCaml toplevel as shell scripts (or, in the case of DOS, 'batch files') are to a standard command shell. The benefits of the OCaml toplevel mostly center around its use as a learning tool and as a test environment for short snippets of code before writing them into a file that will ultimately be compiled for execution. Once you are working within the toplevel, you can exit it by entering the key sequence that delivers an End Of File on your system. On most unices, this requires holding down the Control key and pressing the D key. Check the documentation for your system, or online, for information specific to your own system. You can also exit by entering this command: #quit;; Now that you know how to exit, it might help to know how to start the OCaml toplevel. You do so by entering the following at the command line: ocaml That's basically all there is to it.