In this page, we list some important changes made to ATS/Geizella. In particular, we report changes made to the grammar of ATS.
The sorts for boxed types and viewtypes are introduced. We now use type and viewtype as the sorts for boxed types and viewtypes, respectively. For unboxed types and viewtypes, the sorts are t@ype and viewt@ype, respectively.
Here are two type definitions for boxed and unboxed pairs of integers:
stadef int2_box: type = '(int, int) // boxed tuple stadef int2_flt: t@ype = @(int, int) // flat tuple
For a function declaration, the default function kind is now function (FUNCLOfun) instead of closure (FUNCLOclo). For example, The following function declaration assigns foo the type T1 -<fun1> T2:
fun foo (x: T1): T2 = ...
In order to assign a closure type to foo, the function kind annoation needs to be supplied as follows:
fun foo (x: T1):<clo1> T2 = ...
For each constructor associated with a dataviewtype, we can use refvar patterns to gain access to both the locations of the arguments of the constructor and the views associated with these locations.
In the following example, we first declare a dataviewtype for linked lists:
datatype list_vt (a:viewt@ype+, int) = | {n:nat} list_vt_cons (a, n+1) of (a, list (a, n)) | list_vt_nil (a, 0)
fun{a:t@ype} foreach_list_vt {n:nat} .. (f: (!a) - void, xs: !list_vt (a, n)): int n = case+ xs0 of | cons (!x, !xs) => (f (!x); foreach_list_vt (!xs); fold@ xs0) | nil () => ()
Closures are classified into linear closures (cloptr) and persistent closures (cloref). This is a great change, resulting in global impacts on ATS statically as well as dynamically. With linear closures, it becomes possible to support high-order functional programming in a situation where the memory footprint a program must be kept minimal.