Originale-mail to me for new edition

 

Type identity

 

Type identity is almost straightforward. When one type identifier is declared using another type identifier, without qualification, they denote the same type. Thus, given the declarations

type

  T1 = Integer;

  T2 = T1;

  T3 = Integer;

  T4 = T2;

T1, T2, T3, T4, and Integer all denote the same type. To create distinct types, repeat the word type in the declaration. For example,

type TMyInteger = type Integer;

creates a new type called TMyInteger which is not identical to Integer.

Language constructions that function as type names denote a different type each time they occur. Thus the declarations

type

  TS1 = set of Char;

  TS2 = set of Char;

create two distinct types, TS1 and TS2. Similarly, the variable declarations

var

  S1: string[10];

  S2: string[10];

create two variables of distinct types. To create variables of the same type, use

var S1, S2: string[10];

or

type MyString = string[10];

var

  S1: MyString;

  S2: MyString;

 

Topic groups

 

See also

Assignment-compatibility

Declaraing types

Type comatibility

Type compatibility and identity: Overview

 

 

译文

 

类型等同

 

类型兼容性几乎是简洁明了的。当定义一个类型标识符时使用了另一个类型标识符,并且没有限定词,那么它们表示相同的类型。例如,对于给出的声明

type

  T1 = Integer;

  T2 = T1;

  T3 = Integer;

  T4 = T2;

这里的T1T2T3T4Integer都表示相同的的类型。要创建不同的类型,可以在声明中重复使用保留字type。例如

type TMyInteger = type Integer;

这里创建了叫做TMyInteger的新的类型,它与Integer是不等同的。

对于产生类型名称的语言造句,每次出现都表示不同的类型。对于如下声明

type

  TS1 = set of Char;

  TS2 = set of Char;

这里创建了两个不同的类型,TS1TS2。同样,对于变量声明

var

  S1: string[10];

  S2: string[10];

这里创建了两个类型不同的变量。要创建相同类型的变量,应使用声明

var S1, S2: string[10];

或声明

type MyString = string[10];

var

  S1: MyString;

  S2: MyString;

 

主题组

 

相关主题

赋值兼容

声明类型

类型兼容

类型兼容和等同:概述