标准摘要
[中文适用范围]: CLI 标准库 (ISO/IEC 23271) 提供了可供多种语言使用的通用类型集合。随着 CLI 中泛型的加入,标准库已扩展为包含许多通用泛型类型,特别是集合。但是,目前,这些库不包含许多不同语言中存在的许多简单泛型类型。任何使用这些通用类型的语言都必须实现它们,而不是遵从 CLI 库,从而降低了语言互操作性。本技术报告通过提供许多这些通用类型来解决此问题。通用元组(产品类型)是多种语言的标准:C++(模板对)、Ada、Haskell 和标准 ML (SML)。但是,语言的标准库支持的预定义元组大小数量有所不同;例如,C++ 仅提供一种(对),而 Haskell 提供八种(大小 2 到 9),SML 允许任何大小的元组。本技术报告提供九种(大小 2 到 10)。泛型编程鼓励“高阶”编程,其中泛型函数(方法)采用具有泛型类型的函数(委托)类型参数。示例包括 Ada 的 with 和泛型约束,以及 Haskell 和 SML 中的函数参数。在 CLI 中,函数值以委托的形式提供,因此本提案为函数(返回值)和过程(不返回值)定义了标准泛型委托类型。在许多语言中出现的另外两种类型是可选类型,它包含其他类型的值或指示不存在此类值;以及 either 类型,它包含两种可能类型之一的值并指示存在哪种类型。本提案提供了这两种类型。注意可选类型与 System.Nullable 类型相似,但不同。最后,在现有的泛型语言中,当泛型类型的特定用途不需要特定泛型参数时,需要使用填充类型。通常为此目的提供标准的单值类型,通常称为 Unit 或 Void。本技术报告包括这种类型。 [外文原描述]: The CLI standard libraries (ISO/IEC 23271) provide a collection of common types that can be used by multiple languages. With the addition of generics to the CLI, the standard libraries have been extended to include a number of common generic types, in particular, collections. However, at present, these libraries do not include many simple generic types found in a number of different languages. Any language which uses these common types must implement them rather than deferring to the CLI library, thereby reducing language inter-operability. ISO/IEC TR 25438:2006 addresses this issue by providing a number of these common types.
英文名称Information technology - Common Language Infrastructure (CLI) - Technical Report: Common Generics