# Generic support

SRC Modula-3 includes both quake functions you can use in your m3makefile for instantiating generics, and basic type interfaces you can supply as arguments to those functions.

## Generic Instantiation Functions

Many of the packages that export generic interfaces and modules also define m3build procedures that will instantiate the generic source and add it to the list of Modula-3 sources to be compiled. The instantiated interfaces and modules are created in the build directory, so they won't clutter up your source directory.

array_sort(nm, elt) instantiates the `ArraySort` generics to produce `nmArraySort.i3` and `nmArraySort.m3` which implement a sort for arrays of `elt.T` values.

Array_sort(nm, elt) like `array_sort`, but also makes the interface available to importers outside the current package.

list(nm, elt) instantiates the `List` generics to produce `nmList.i3` and `nmList.m3` which implement linked lists of `elt.T` values.

List(nm, elt) like `list`, but also makes the interface available to importers outside the current package.

list_sort(nm, elt) instantiates the `ListSort` generics to produce `nmListSort.i3` and `nmListSort.m3` which implement a sorting procedure for lists of `elt.T` values. This procedure assumes that `list(nm,elt)` has been called.

List_sort(nm, elt) like `list_sort`, but also makes the interface available to importers outside the current package.

pqueue(nm, elt) instantiates the `PQueue` generics to produce `nmPQ.i3` and `nmPQ.m3` which implement a priority queue of `elt.T` values.

Pqueue(nm, elt) like `pqueue`, but also makes the interface available to importers outside the current package.

sequence(nm, elt) instantiates the `Sequence` generics to produce `nmSeq.i3`, `nmSeqRep.i3` and `nmSeq.m3` which implement a sequence of `elt.T` values.

Sequence(nm, elt) like `sequence`, but also makes the interfaces available to importers outside the current package.

sorted_table(nm, key, value) instantiates the `SortedTable` generics to produce `nmSortedTbl.i3` and `nmSortedTbl.m3` which implement a sorted table mapping from type `key.T` to `value.T`.

Sorted_table(nm, key, value) like `sorted_table`, but also makes the interface available to importers outside the current package.

table(nm, key, value) instantiates the `Table` generics to produce `nmTbl.i3` and `nmTbl.m3` which implement a table mapping from type `key.T` to `value.T`.

Table(nm, key, value) like `table`, but also makes the interface available to importers outside the current package.

## Interfaces for Basic Types

Many generic interfaces, such as `Table` and `Sequence`, require one or more of their argument interfaces to have a certain form. For example, the expect the principle type of the argument interface to be named "`T`", and they expect the interface to define certain constants and procedures. The basic Modula-3 library defines the following interfaces for basic types that can be used as arguments to such generics (each interface's principle type is shown in parentheses):

- `Text` (`TEXT`)
- `Atom` (`Atom.T`)
- `Refany` (`REFANY`)
- `Char` (`CHAR`)
- `Boolean` (`BOOLEAN`)
- `Integer` (`INTEGER`)
- `RealType` (`REAL`)
- `LongrealType` (`LONGREAL`)

But you aren't limited to these interfaces in your generic instantiations. You can also supply your own interface as an argument to a generic instantiation, so long as it meets all of the generic's requirements.

    Last modified on Wed Aug 21 14:23:18 PDT 1996 by heydon
         modified on Thu Jun  1 08:18:55 PDT 1995 by kalsow
         modified on Thu Jan  7 18:40:57 PST 1993 by muller