modula-2 home

  Win32 API  


Type declarations

Set types

Set types have values that specify a subset of a set of objects.  The objects can be:

  • positive integers
  • characters
  • an enumeration type
  • a subrange of any of the above

To specify a set type, use:

SET OF TypeSpecification;

PACKEDSET OF TypeSpecification;

TypeSpecification is called the base type of the set.

You can think of a set type as having a Boolean membership flag for each value in the base type.

Modula-2 supports two different types of sets, SET and PACKEDSET. The only difference between the two is how a compiler is allowed to implement a set type. PACKEDSET types are implemented such that each ordinal value in the set maps directly to individual bits in the memory storage for the set type. The first ordinal value occupies the first bit and this continues until the last bit. A compiler is allowed to implement the SET type in any way it chooses.

Note: Stony Brook Modula-2 implements the SET type the same as the PACKEDSET type.



SET OF [0..65535]

SET OF ['A'..'Z']

SET OF (Red, Green, Blue)

An object with the type of the last example above can have any of the following values:

{Red, Green}
{Red, Blue}
{Green, Blue}
{Red, Green, Blue}


  • Wirth N: Programming in Modula-2, 3rd ed. Springer Verlag, Berlin, 1985.
  • Stony Brook Modula-2 documentation. Used with permission. Note: Stony-Brook M2 offers an extended syntax with features not described here. Stony Brook M2 users are encouraged to visit the Stony Brook website and to consult the Stony Brook help system.