Skip to content

Function like Construct

Artyom Shalkhakov edited this page May 4, 2017 · 2 revisions

Source: Google group discussion

In ATS, we can use something like '(1, 2) and @{x=1, y=2} to create tuples and records. Instead of adding lots of fancy syntax for creating arrays, lists, and whatever coming up in the future, ATS provides a set of function-like constructs to construct them. These primitives are not really functions in ATS, but they can be used like function calls. In this way, we don't need to memorize strange syntax. Some of the constructs are $list, $list_vt, $tuple, $tuple_vt, and $raise.

Code example for List0 int and list0 int

// ($list {int} (0, 2, 3)) constructs a list of type List0 int.
val xs = ($list {int} (0, 2, 3)): List0 int

// Convert the list into the type we want.
val xs = (g0ofg1 xs): list0 int

Code example for arrpsz (int, 10) and array0 int

val xs = $arrpsz{int} (
         2, 9, 8, 4, 5, 3, 1, 7, 6, 0): arrpsz(int, 10) (* end of [val] *)
val xs = array0 (xs): array0 int
Clone this wiki locally