Copyright © 1996, 1997 Lucent Technologies Inc. All rights reserved.

4.2 Data types

The syntax of data types is


data-type: byte int big real string tuple-type array of data-type list of data-type chan of data-type adt-type ref adt-type module-type module-qualified-type type-name data-type-list: data-type data-type-list , data-type
Objects of most data types have value semantics; when they are assigned or passed to functions, the destination receives a copy of the object. Subsequent changes to the assigned object itself have no effect on the original object. The value types are byte, int, big, real, string, the tuple types, and abstract data types or adt. The rest have reference semantics. When they are assigned, the quantity actually assigned is a reference to (a pointer to) an underlying object that is not copied; thus changes or operations on the assigned value affect the original object. Reference types include lists, arrays, channels, modules, and ref adt types.

4.2.1 Basic types

The five basic data types are denoted by byte, int, big, real, and string.

Bytes are unsigned 8-bit quantities.

Integers (int) are 32-bit signed quantities represented in two's complement notation. Large integers (big) are 64-bit signed quantities represented in two's complement notation.

Real numbers (real) are 64-bit quantities represented in the IEEE long floating notation.

The byte, int, big, and real types are collectively called arithmetic types.

Strings are rows of Unicode characters. They may be concatenated and extended character-by-character. When a string is indexed with a single subscript, it yields an integer with the Unicode encoding of the character; when it is indexed by a range, it yields another string.

4.2.2 Tuple type

The tuple type, denoted


tuple-type: ( data-type-list )
is a type consisting of an ordered collection of two or more objects, each having its own data type. For each tuple type, the types of the members are fixed, but need not be identical; for example, a function might return a tuple containing an integer and a string. Each tuple type is characterized solely by the the order and identity of the types it contains. Objects of tuple type may be assigned to a list of identifiers (to pick out the components), and a parenthesized, comma-separated list of expressions denotes a tuple.

4.2.3 Array types

The array type describes a dynamically-sized row of objects, all of the same type; it is indexed starting from 0. An array type is denoted by


array of data-type
The size of an array is not part of its type; instead it is part of the value. The data-type may itself be an array, to achieve a multidimensional array.

4.2.4 List types

A list is a sequence of like-typed objects; its denotation is


list of data-type
A list is a stack-like object, optimized for a few operations: get the head (the first object), get the tail (the rest of the list), place an object at the beginning.

4.2.5 Channel types

A channel, whose type is written


chan of data-type
is a communication mechanism capable of sending and receiving objects of the specified type to another agent in the system. Channels may be used to communicate between local processes; using library procedures, they may be connected to named destinations. In either case send and receive operations may be directed to them. For example,
	chan of (int, string)
is the type of a channel that transmits tuples consisting of an integer and an string. Once an instance of such a channel (say c) has been declared and initialized, the statement
	c <-= (123, "Hello");
sends such a tuple across it.

4.2.6 Abstract data types

An abstract data type or adt is an object that can contain data objects of several different types and declare functions that operate on them. The syntax for declaring an adt is given later. Once an adt has been declared, the identifier associated with it becomes a data-type name.


adt-type: identifier module-qualified-type

There is also a ref adt type representing a reference (pointer) to an adt. It is denoted


ref adt-type
where the identifier is the name of an adt type.

4.2.7 Module types

A module type name is an identifier:


module-type: identifier
The identifier is declared as a module identifier by a module-declaration, as described in §6.5 below. An object of module type serves as a handle for the module, and is used to access its functions.

4.2.8 Module-qualified type

When an adt is declared within a module declaration, the type name of that adt is not generally visible to the rest of the program unless a specific import request is given (see §§6.6, 10 below). Without such a request, when adt objects implemented by a module are declared by a client of that module, the adt type name is qualified:


module-qualified-type: identifier -> identifier
Here the first identifier is either the name of a module or a variable of the module type; the second is the name of a type mentioned in the module declaration.

4.2.9 Named types

Finally, data types may be named, using a type declaration; this is discussed in §6.4 below.


type-name: identifier

05/Jun/97