(This is a post for CS320 at Boston University.)

You will be reading some very basic aspects of ATS.

Functional Programming

ATS is primarialy a functional programming language. Compared to imperative languages like C and Java, which expose control flows, machine models and states, functional programs mostly care about defining/evaluating values. There aren't any explicit control flows, and they are stateless.

Your code will most likely be a set of files that defines a variety of values, including simple primitive values, complex values like trees/lists, and also functions.

File Extensions

(Taken from Google Group ats-lang-users by Hongwei Xi).

Two primary file name extensions used by ATS are .sats and .dats.

A .sats file is simply a special case of .dats file that does not contain implementation code for values and functions. Also, in a .sats file, value and function declarations should not follow the keyword extern.

For instance, in a .sats file, we can have the following declaration:

fun foo (x: int, y: int): bool

The same declaration needs to be written as follows in a .dats file:

extern fun foo (x: int, y: int): bool

Defining Values

To define primitive values, use keyword val:

val x:int = 3
val y = ~5 + x
val z:string = "hello"
val b = true

To declare function values, use keyword fun:

fun add(x:int, y:int): int
fun ite(c:bool, x:int, y:int): int

To actually define function values, use keyword implement:

implement add(x, y) = x + y
implement ite(c, x, y) = if c then x else y
implement main0 () = let
    val a = add(3, 5)
    val b = ite(a = 8, 0, ~1)
    val () = println! (b)

Compile and Run

The patscc utility is a wrapper that will call various commands to compile source code, link objects and output an executable. Internally, patsopt will compile ATS code into C code, and then gcc will help compile C code into binary code.

Its basic usage is shown here

patscc -o [output] [inputs]