© Jørgen Steensgaard-Madsen, Copenhagen, 2006
Abstract type operators                                                  

An operation may be polymorphic, i.e. it may be used with operand types that vary from one application to another. Its description then depends on a locally defined type name to express the kind of acceptable variations. A description may use a locally defined type name also to introduce an abstract type, i.e. a type presented to a user in terms of operations that are characteristic for the type.
An abstract type is appropriate for a simple operation that allows a user to query for properties related to files in a UNIX system. A user may want to know whether a given string identifies a file and find out what kind of file it possibly is. An example may be
If there is a file , a query like may be appropriate.
The names absent and directory may be of the same type and distinct from other types known to the user. Furthermore, the names are useful in this context only, so their type is made unknown elsewhere. It can be considered a property of the is_file operation that it introduces a context of discourse where the names for file properties are introduced along with their type so that they cannot be confused with other entities.
A corresponding description of is_file that agrees with its use above is:

[ is_file(Path:string)
    [Kind OF Attr

The is_file operation requires two clauses of which the second must be of type Attr. However, no value of type Attr is known outside the second clause, and the only ones known within are the seven mentioned in the description.
This is a minimalistic, though practical example. The example of support for pairs is more substantial:
[ pairs W
    [ Members OF 2 PAIR
        [ pair OF A, B(X:A,Y:B):A B Pair ]
        [ fst OF A, B(V:A B Pair):A ]
        [ snd OF A, B(V:A B Pair):B ]
        [ == OF A, B {A==A,B==B}(A B Pair,A B Pair):int ]
        : W ]
    : W ]

The signature can be read as describing a class of objects with operations for building and decomposing values of types described by means of the dyadic type constructor PAIR. The equality operator is defined on such values provided the equality operator is defined for the component values.
A more detailed explanation of pairs and associated operations will be given later. In particular there will be more to be said about the type identifier W and an alternative to the equality operator.


Demo language
·Implementation tool

Interpreter construction

Deep- and surface structures
Design issues
·Abstract type operatorss
Description of operator
Name introduction
Data abstraction and control

File translated from TEX by TTH, version 3.33.
On 18 Oct 2006, 16:47.
SourceForge.net Logo