Datatype representation

Say you have a datatype declared as follows:

datatype foo = A of () | B of (int) | C of (int, double)

There are three types foo_A, foo_B, and foo_C associated with foo which are
for values constructed by
A, B, and C, respectively. These types can be described using C-syntax as
follows:

typedef intptr_t foo_A;
typedef struct { int atslab_0 ; } *foo_B ;
typedef struct { int atslab_0 ; double atslab_1 ; } *foo_C ;

Note that the value A() is represented as an integer (intptr_t is for
integers that are as wide as a pointer).

Say you have a datatype for which every constructor is unary. For instance,

datatype weekday =
| Monday
| Tuesday
| Wednesday
| …

Then this is datatype is like an enum type in C. Internally, Monday(),
Tuesday()
and Wednesday() are represented by 0, 1, and 2 because they the first,
second
and third constructors associated with the datatype weekday.

You can use the following code to test what I said about
the datatype weekday:

local
//
staload
UN = “prelude/SATS/unsafe.sats”
//
macdef
ptr2int (x) =
$UN.cast{int}($UN.cast{intptr}(,(x)))
//
in (in-of-local)

val-(0) = ptr2int(Monday())
val-(1) = ptr2int(Tuesday())
val-(2) = ptr2int(Wednesday())
val-(3) = ptr2int(Thursday())
val-(4) = ptr2int(Friday())

end // end of [local]On Tuesday, January 14, 2014 3:18:28 PM UTC-5, gmhwxi wrote:

Say you have a datatype declared as follows:

datatype foo = A of () | B of (int) | C of (int, double)

There are three types foo_A, foo_B, and foo_C associated with foo which
are for values constructed by
A, B, and C, respectively. These types can be described using C-syntax as
follows:

typedef intptr_t foo_A;
typedef struct { int atslab_0 ; } *foo_B ;
typedef struct { int atslab_0 ; double atslab_1 ; } *foo_C ;

Note that the value A() is represented as an integer (intptr_t is for
integers that are as wide as a pointer).

Say you have a datatype for which every constructor is unary. For instance,

datatype weekday =
| Monday
| Tuesday
| Wednesday
| …

Then this is datatype is like an enum type in C. Internally, Monday(),
Tuesday()
and Wednesday() are represented by 0, 1, and 2 because they the first,
second
and third constructors associated with the datatype weekday.