Compiling ATS code

ATS code is first compiled into code written in a very restricted subset of C. The generated C code from ATS source can then be compiled into object code or transpiled into code written in a variety of programming languages including Javascript, PHP, Perl, Python, Erlang, Scheme, Clojure, R, etc.

The command patsopt is for compiling ATS code into C code, which can then be compiled into object code by a standard C compiler such as gcc and clang. The command patscc is a convenience wrapper around patsopt, and it can be called, for instance, to compile ATS code into object code directly. For compiling a single-file ATS program into a standalone executable, the command myatscc can be used instead.

As an example, let us assume that the following code (for printing out the string "Hello, world!" plus a newline) is stored in a file of the name hello.dats:

// val _ = print ("Hello, world!\n") // implement main0 () = () // a dummy for [main] //

One can produce an executable of the name hello_dats by simply executing the command-line below:


myatscc hello.dats

When the command ./hello_dats is executed, the expected message is printed onto the console. Please give it a try!

When a project consisting of multiple files written in ATS needs to be compiled, I often construct a Makefile and then rely on the make utility to streamline the compilation process.