What is a boxed type in ATS?

In ATS, there are two sorts ‘type’ and ‘t@ype’ (or ‘t0ype’) where the
former is for boxed types
and the latter for (potentially) unboxed types. A boxed type is really just
a special case of unboxed type.

Internally, any type T can be treated as a boxed type if sizeof(T) =
sizeof(ptr) (where ptr is the type for
pointers).

Every datatype in ATS is a boxed type; every type formed using the syntax
’{…} is
a boxed (tuple/record) type; etc. Primitive types like ‘char’, ‘int’,
‘double’ are not boxed types.

The type ‘string’ (for strings) is not considered a boxed type by default.
Also, any function types
(that is, types for functions) are not considered a boxed type by default.
However, there are boxed
versions for these types. For instance, boxed(string) is the boxed version
of ‘string’, which is internally
the same as ‘string’; boxed((int, int) -> bool) is the boxed version of
’(int, int) -> bool’; etc.

val A = "A"
val A1 = box(A) // A1: boxed(string)
val A2 = unbox(A) // A2: string

In the above code, A, A1, and A2 are all the same value internally.

In practice, the need for types like boxed(string) is very are; it happens
most likely in a situation where
polymorphic functions (rather than function templates) are called.

thanks, understood.

What is a boxed string? Is it a pointer-to-a-pointer? To me, "boxed"
means that it is on the heap. Strings are pointers to things on the
heap usually, no?

A string is already boxed.

A boxed string is the same as a string.

The word ‘boxed’ in ‘boxed(string)’ is more like a proof indication:
proving that ‘string’ is boxed.

Say we have

abstype T1 = ptr
abstype T2 = unit // unit is a datatype

In ATS, T1 is considered a type whose size equal that of a pointer.
However, T1 is not considered a boxed type by default. You could
use boxed(T1) for the boxed version of T1: T1 and boxed(T1) are the
same internally.

T2 is a boxed type.

I mention this distinction here mainly for the pure sake of documentation.
I don’t really feel that the distinction is so relevant. It may become
relevant
if one uses a lot of polymorphic functions. But that is a big IF.On Tuesday, July 21, 2015 at 2:16:28 PM UTC-4, Raoul Duke wrote:

What is a boxed string? Is it a pointer-to-a-pointer? To me, “boxed”
means that it is on the heap. Strings are pointers to things on the
heap usually, no?