ISO IEC TR 25438-2006 Information technology - Common Language Infrastructure (CLI) - Technical Report Common Generics《信息技术 通用语言结构(CLI) 技术报告 普通遗传学》.pdf

上传人:livefirmly316 文档编号:1257425 上传时间:2019-09-02 格式:PDF 页数:70 大小:511KB
下载 相关 举报
ISO IEC TR 25438-2006 Information technology - Common Language Infrastructure (CLI) - Technical Report Common Generics《信息技术 通用语言结构(CLI) 技术报告 普通遗传学》.pdf_第1页
第1页 / 共70页
ISO IEC TR 25438-2006 Information technology - Common Language Infrastructure (CLI) - Technical Report Common Generics《信息技术 通用语言结构(CLI) 技术报告 普通遗传学》.pdf_第2页
第2页 / 共70页
ISO IEC TR 25438-2006 Information technology - Common Language Infrastructure (CLI) - Technical Report Common Generics《信息技术 通用语言结构(CLI) 技术报告 普通遗传学》.pdf_第3页
第3页 / 共70页
ISO IEC TR 25438-2006 Information technology - Common Language Infrastructure (CLI) - Technical Report Common Generics《信息技术 通用语言结构(CLI) 技术报告 普通遗传学》.pdf_第4页
第4页 / 共70页
ISO IEC TR 25438-2006 Information technology - Common Language Infrastructure (CLI) - Technical Report Common Generics《信息技术 通用语言结构(CLI) 技术报告 普通遗传学》.pdf_第5页
第5页 / 共70页
点击查看更多>>
资源描述

1、 Reference number ISO/IEC TR 25438:2006(E) ISO/IEC 2006TECHNICAL REPORT ISO/IEC TR 25438 First edition 2006-08-01 Information technology Common Language Infrastructure (CLI) Technical Report: Common Generics Technologies de linformation Infrastructure commune de langage (ICL) Rapport technique: Gnri

2、ques communs ISO/IEC TR 25438:2006(E) PDF disclaimer This PDF file may contain embedded typefaces. In accordance with Adobes licensing policy, this file may be printed or viewed but shall not be edited unless the typefaces which are embedded are licensed to and installed on the computer performing t

3、he editing. In downloading this file, parties accept therein the responsibility of not infringing Adobes licensing policy. The ISO Central Secretariat accepts no liability in this area. Adobe is a trademark of Adobe Systems Incorporated. Details of the software products used to create this PDF file

4、can be found in the General Info relative to the file; the PDF-creation parameters were optimized for printing. Every care has been taken to ensure that the file is suitable for use by ISO member bodies. In the unlikely event that a problem relating to it is found, please inform the Central Secretar

5、iat at the address given below. ISO/IEC 2006 All rights reserved. Unless otherwise specified, no part of this publication may be reproduced or utilized in any form or by any means, electronic or mechanical, including photocopying and microfilm, without permission in writing from either ISO at the ad

6、dress below or ISOs member body in the country of the requester. ISO copyright office Case postale 56 CH-1211 Geneva 20 Tel. + 41 22 749 01 11 Fax + 41 22 749 09 47 E-mail copyrightiso.org Web www.iso.org Published in Switzerland ii ISO/IEC 2006 All rights reservedISO/IEC TR 25438:2006(E) ISO/IEC 20

7、06 All rights reserved iii Contents Page Foreword. v Introduction . vi 1 Scope . 1 2 Rationale 1 2.1 Reference vs. value tuples. 1 2.2 Interaction with other standard types. 2 3 Overview 2 3.1 Tuple types 2 3.2 Function and procedure types 2 3.3 Unit . 2 3.4 Optional . 3 3.5 Either 3 4 Action delega

8、tes . 3 4.1 System.Action delegate . 3 4.2 System.Action delegate 4 4.3 System.Action delegate . 5 4.4 System.Action delegate. 6 4.5 System.Action delegate 8 5 System.DelegateCast class . 9 5.1 DelegateCast.ToFunction(System.Predicate) method. 10 5.2 DelegateCast.ToPredicate(System.Function) method.

9、 10 5.3 DelegateCast.ToFunction(System.Converter) method. 11 5.4 DelegateCast.ToConverter(System.Function) method. 12 5.5 DelegateCast.ToFunction(System.Comparison) method . 12 5.6 DelegateCast.ToComparison(System.Function) method . 13 6 System.Either Structure . 13 6.1 Either.Equals(System.Object)

10、method 15 6.2 Either.Equals(Either) method . 16 6.3 Either.First property 17 6.4 Either.GetHashCode() method.17 6.5 Either.IsFirst property. 18 6.6 Either.IsSecond property 19 6.7 Either.op_Equality(Either, Either) method. 19 6.8 Either.op_Inequality(Either, Either) method 20 6.9 Either.Second prope

11、rty. 21 6.10 Either.MakeFirst(A aValue) method. 22 6.11 Either.MakeSecond(B bValue) method . 22 6.12 Either.ToString() method 23 6.13 Either(A) constructor 23 6.14 Either(B) constructor 24 6.15 A Either.op_Explicit(System.Either) method 25 6.16 B Either.op_Explicit(System.Either) method 26 6.17 Eith

12、er.op_Implicit(A) method . 27 6.18 Either.op_Implicit(B) method . 28 7 Function Delegates. 29 7.1 System.Function delegate . 29 7.2 System.Function delegate 30 7.3 System.Function delegate . 31 ISO/IEC TR 25438:2006(E) iv ISO/IEC 2006 All rights reserved7.4 System.Function delegate. 32 7.5 System.Fu

13、nction delegate 33 7.6 System.Function delegate 35 8 System.Optional structure. 36 8.1 Optional(T) constructor 38 8.2 Optional.CompareTo(System.Object) method. 38 8.3 Optional.CompareTo(Optional) method. 40 8.4 Optional.Equals(System.Object) method. 41 8.5 Optional.Equals(Optional) method. 42 8.6 Op

14、tional.FromNullable(Nullable) method. 43 8.7 Optional.FromOptional(System.Optional) method . 44 8.8 Optional.GetHashCode() method45 8.9 Optional.GetValueOrDefault() method 45 8.10 Optional.GetValueOrDefault(T) method . 46 8.11 Optional.HasValue property 46 8.12 Optional.op_Equality(Optional, Optiona

15、l) method. 47 8.13 Optional.op_Explicit(System.Optional) method . 48 8.14 Optional.op_Implicit(T) method 49 8.15 Optional.op_Inequality(Optional, Optional) method 50 8.16 Optional.ToNullable(Optional) method. 51 8.17 Optional.ToOptional(T) method 51 8.18 Optional.ToString() method. 52 8.19 Optional.

16、Value property. 53 8.20 Optional.INullableValue.Value property . 53 9 Tuple structures System.Tuple System.Tuple. 54 9.1 Tuple() constructors. 56 9.2 Tuple.Equals(System.Object) method 56 9.3 Tuple.Equals(Tuple) method. 57 9.4 Tuple.ItemA, Tuple.ItemB, Tuple.ItemJ field 58 9.5 Tuple.GetHashCode() me

17、thod. 58 9.6 Tuple.op_Equality(Tuple, Tuple) method 59 9.7 Tuple.op_Implicit(KeyValuePair) method 60 9.8 Tuple.op_Implicit(Tuple) method 60 9.9 Tuple.op_Inequality(Tuple, Tuple) method . 61 9.10 Tuple.ToString() method 62 10 System.Unit enum. 62 10.1 Unit.Unit field. 63 ISO/IEC TR 25438:2006(E) ISO/

18、IEC 2006 All rights reserved v Foreword ISO (the International Organization for Standardization) and IEC (the International Electrotechnical Commission) form the specialized system for worldwide standardization. National bodies that are members of ISO or IEC participate in the development of Interna

19、tional Standards through technical committees established by the respective organization to deal with particular fields of technical activity. ISO and IEC technical committees collaborate in fields of mutual interest. Other international organizations, governmental and non-governmental, in liaison w

20、ith ISO and IEC, also take part in the work. In the field of information technology, ISO and IEC have established a joint technical committee, ISO/IEC JTC 1. International Standards are drafted in accordance with the rules given in the ISO/IEC Directives, Part 2. The main task of the joint technical

21、 committee is to prepare International Standards. Draft International Standards adopted by the joint technical committee are circulated to national bodies for voting. Publication as an International Standard requires approval by at least 75 % of the national bodies casting a vote. In exceptional cir

22、cumstances, the joint technical committee may propose the publication of a Technical Report of one of the following types: type 1, when the required support cannot be obtained for the publication of an International Standard, despite repeated efforts; type 2, when the subject is still under technica

23、l development or where for any other reason there is the future but not immediate possibility of an agreement on an International Standard; type 3, when the joint technical committee has collected data of a different kind from that which is normally published as an International Standard (“state of

24、the art”, for example). Technical Reports of types 1 and 2 are subject to review within three years of publication, to decide whether they can be transformed into International Standards. Technical Reports of type 3 do not necessarily have to be reviewed until the data they provide are considered to

25、 be no longer valid or useful. Attention is drawn to the possibility that some of the elements of this document may be the subject of patent rights. ISO and IEC shall not be held responsible for identifying any or all such patent rights. ISO/IEC TR 25438 was prepared by Ecma International (as Ecma T

26、R/89) and was adopted, under a special “fast-track procedure”, by Joint Technical Committee ISO/IEC JTC 1, Information technology, in parallel with its approval by national bodies of ISO and IEC. ISO/IEC TR 25438:2006(E) vi ISO/IEC 2006 All rights reservedIntroduction This Technical Report defines a

27、 collection of types that are intended to enhance the common language nature of the CLI, by facilitating language inter-operation. The collection includes generic tuples, functions, actions, optional value representation, a type that can contain a value of one of two different types, and a utility f

28、iller type. These types are experimental and will be considered for inclusion in a future version of the CLI International Standard. A reference implementation, written in C#, is included (see the accompanying file CommonGenericsLibrary.cs). This implementation source is also available from http:/.n

29、z/ecma. A binary version is also available from that site, along with any updates to the proposal. Feedback on these types is encouraged. (Please send comments to .nz.) TECHNICAL REPORT ISO/IEC TR 25438:2006(E ISO/IEC 2006 All rights reserved 1 Information technology Common Language Infrastructure (

30、CLI) Technical Report: Common Generics 1 Scope 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 p

31、articular, 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. This

32、Technical Report addresses this issue by providing a number of these common types. Generic tuples (product types) are standard in a number of languages: C+ (template Pair), Ada, Haskell, and Standard ML (SML). However, languages differ in the number of pre-defined tuple sizes supported by their stan

33、dard libraries; e.g. C+ provides just one (Pair) while Haskell provides eight (sizes 2 to 9) and SML allows any size of tuple. This Technical Report provides nine (sizes 2 to 10). Generic programming encourages “higher order” programming where generic functions (methods) take function (delegate) typ

34、e arguments that have generic types. Examples include Adas with and generic constraints, and function arguments in Haskell and SML. In the CLI, function values are provided in the form of delegates, so this proposal defines standard generic delegate types for functions (which return a value) and pro

35、cedures (which do not). Another two types that occur in a number of languages are an optional type, which either contains a value of some other type or an indication that such a value is not present; and an either type, which holds a value of one of two possible types and an indication of which one

36、is present. This proposal provides both of these. Note The optional type is similar to, but different from, the type System.Nullable. Finally, in existing generic languages, a need has been found for a filler type to be used when a particular generic parameter is not required for a particular use of

37、 the generic type. A standard one-value type is often provided for this purpose, often called Unit or Void. This Technical Report includes such a type. 2 Rationale 2.1 Reference vs. value tuples In some languages (such as C+ and Ada) tuple types can be value or reference types, while in others (such

38、 as Haskell and SML) they are always reference types. This implementation provides only value type tuples (which can contain value or reference types). Boxed versions of these types can be used when reference versions are required. Named boxed types would, of course, help greatly here, but these are

39、 not currently provided by the CLI Standard. A simple generic type, such as Boxed, can be written to address this issue. Such a type has been made available in the reference implementation of this proposal. However it is not being considered for standardization at this time. ISO/IEC TR 25438:2006(E)

40、 2 ISO/IEC 2006 All rights reserved2.2 Interaction with other standard types The CLI Standard contains six types related to those in this proposal. These are: System.Action: This type is just the first member of this collections set of action types. As it is already standardized it is not included h

41、ere. System.Comparison: This type is equivalent to this collections Function. Conversion methods are provided. System.Converter: This type is equivalent to this collections Function. Conversion methods are provided. System.Nullable: This type is a restricted version of this collections Optional. The

42、 difference is that Nullable is restricted to non-nullable value types, whereas Optional can also wrap reference types and nullable value types. Both these choices are useful in different applications, so there is no clash between these two types. This proposal includes operators on the Optional typ

43、e to convert to/from Nullable values. System.Predicate: This type is equivalent to this collections Function. However as the CLI does not support type synonyms, these two types are (unfortunately) not equivalent. A separate static class provides methods to convert between these two types. The method

44、s are in a separate class as additional methods cannot be declared on delegate types. System.Collections.Generic.KeyValuePair: This is just a differently named equivalent of this collections Tuple. Conversion operators are provided on Tuple to convert to/from KeyValuePair. 3 Overview 3.1 Tuple types

45、 Tuples are provided as value types with public fields, which mirrors their typical usage in current languages. Overloading on arity is leveraged to provide eight standard tuple types. The fields are named ItemA, ItemB, , ItemI. A single n-ary constructor is provided to easily define all fields. An

46、Equals() method is provided and defined as the component fields being equal according to their Equals() methods. The corresponding GetHashCode() method and op_Equality and op_Inequality methods are provided. ToString() is overridden to provide the typical tuple parenthesized notation. For tuples of

47、size 2, methods are provided to convert to/from values of type System.Collections.Generic.KeyValuePair. 3.2 Function and procedure types Standard delegates are provided for function types (System.Function). Delegates are defined for 0 to 5 argument functions and 0 and 2 to 5 argument procedures. (Th

48、e single argument procedure is already included in the CLI Standard.) 3.3 Unit The Unit type is a filler type. This is useful, for example, when an existing generic type is used, but one of its type arguments is not required for the particular application. ISO/IEC TR 25438:2006(E) ISO/IEC 2006 All r

49、ights reserved 3 3.4 Optional The Optional type represents either a value of type A, or the lack of a value. A value of this type is immutable and provides two constructors, one providing a value, the other for providing no value. Properties are provided to test for validity and to obtain the value. An exception is thrown if an attempt to access a non- existent value. 3.5 Either The Either type represents either a value of type A, or a value of type B. A value of this type is immutable. P

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 标准规范 > 国际标准 > 其他

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1