Information technology — Common Language Infrastructure (CLI) — Technical Report: Common Generics

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.

Technologies de l'information — Infrastructure commune de langage (ICL) — Rapport technique: Génériques communs

General Information

Status
Published
Publication Date
27-Jul-2006
Current Stage
9093 - International Standard confirmed
Completion Date
30-Oct-2013
Ref Project

Buy Standard

Technical report
ISO/IEC TR 25438:2006 - Information technology -- Common Language Infrastructure (CLI) -- Technical Report: Common Generics
English language
63 pages
sale 15% off
Preview
sale 15% off
Preview
Technical report
ISO/IEC TR 25438:2006 - Information technology -- Common Language Infrastructure (CLI) -- Technical Report: Common Generics
English language
63 pages
sale 15% off
Preview
sale 15% off
Preview

Standards Content (Sample)

TECHNICAL ISO/IEC
REPORT TR
25438
First edition
2006-08-01

Information technology — Common
Language Infrastructure (CLI) —
Technical Report: Common Generics
Technologies de l'information — Infrastructure commune de
langage (ICL) — Rapport technique: Génériques communs




Reference number
ISO/IEC TR 25438:2006(E)
©
ISO/IEC 2006

---------------------- Page: 1 ----------------------
ISO/IEC TR 25438:2006(E)
PDF disclaimer
This PDF file may contain embedded typefaces. In accordance with Adobe's 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 the editing. In
downloading this file, parties accept therein the responsibility of not infringing Adobe's 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 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 Secretariat 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 address below or
ISO's 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 copyright@iso.org
Web www.iso.org
Published in Switzerland

ii © ISO/IEC 2006 – All rights reserved

---------------------- Page: 2 ----------------------
ISO/IEC TR 25438:2006(E)
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 delegates . 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. 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) 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 property. 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 Either.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 2006 – All rights reserved iii

---------------------- Page: 3 ----------------------
ISO/IEC TR 25438:2006(E)
7.4 System.Function delegate. 32
7.5 System.Function 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 Optional.FromNullable(Nullable) method. 43
8.7 Optional.FromOptional(System.Optional) method . 44
8.8 Optional.GetHashCode() method.45
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, Optional) 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.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() method. 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

iv © ISO/IEC 2006 – All rights reserved

---------------------- Page: 4 ----------------------
ISO/IEC TR 25438:2006(E)
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 International 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 with 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 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 circumstances, 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 technical 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 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 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 TR/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 2006 – All rights reserved v

---------------------- Page: 5 ----------------------
ISO/IEC TR 25438:2006(E)
Introduction
This Technical Report defines a 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 filler
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://kahu.zoot.net.nz/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 ecmacli@zoot.net.nz.)

vi © ISO/IEC 2006 – All rights reserved

---------------------- Page: 6 ----------------------
TECHNICAL REPORT ISO/IEC TR 25438:2006(E

Information technology — Common Language Infrastructure
(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 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. This 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 standard 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) type arguments that have generic types. Examples include Ada’s 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
procedures (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 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 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
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 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 2006 – All rights reserved 1

---------------------- Page: 7 ----------------------
ISO/IEC TR 25438:2006(E)
2.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 collection's set of action types. As it is already
standardized it is not included here.
System.Comparison: This type is equivalent to this collection's Function. Conversion methods
are provided.
System.Converter: This type is equivalent to this collection's Function. Conversion methods are
provided.
System.Nullable: This type is a restricted version of this collection's Optional. The 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 type to convert to/from Nullable
values.
System.Predicate: This type is equivalent to this collection's 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 methods 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 collection's
Tuple. Conversion operators are provided on Tuple to convert to/from KeyValuePair.
3 Overview
3.1 Tuple types
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 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 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<>) and procedures (System.Action<>).
Delegates are defined for 0 to 5 argument functions and 0 and 2 to 5 argument procedures. (The 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.
2 © ISO/IEC 2006 – All rights reserved

---------------------- Page: 8 ----------------------
ISO/IEC TR 25438:2006(E)
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. Properties are provided to test which type of value is present and to obtain the value. An exception
is thrown if an attempt to access the value of one type is made when a value of the other type is present.
4 Action delegates
4.1 System.Action delegate
[ILAsm]
.class public auto ansi sealed System.Action
    extends System.Delegate
{
 .method public hidebysig newslot virtual
     instance void Invoke()
}
[C#]
public delegate void Action();
Assembly Info:
• Name:
• Public Key:
• Version:
• Attributes:
o CLSCompliantAttribute(true)
Implements:
• System.ICloneable
© ISO/IEC 2006 – All rights reserved 3

---------------------- Page: 9 ----------------------
ISO/IEC TR 25438:2006(E)
Summary:
Represents a method that performs an action.
Parameters:
Inherits From: System.Delegate

Library: BCL

Description
A generic delegate type for zero-argument, methods which perform an action (return void).
4.2 System.Action delegate
[ILAsm]
.class public auto ansi sealed System.Action`2
    extends System.Delegate
{
 .method public hidebysig newslot virtual
     instance void Invoke(!0 argA,
                !1 argB)
}
[C#]
public delegate void Action
           (A argA,
           B argB
           );
Assembly Info:
• Name:
• Public Key:
• Version:
• Attributes:
o CLSCompliantAttribute(true)
Implements:
• System.ICloneable
4 © ISO/IEC 2006 – All rights reserved

---------------------- Page: 10 ----------------------
ISO/IEC TR 25438:2006(E)
Summary:
Represents a method that performs an action using the supplied arguments.
Parameters:
Parameter Description
argA The first argument to the action.
argB The second argument to the action.

Inherits From: System.Delegate

Library: BCL

Description
A generic delegate type for two-argument methods, which perform an action (return void).
4.3 System.Action delegate
[ILAsm]
.class public auto ansi sealed System.Action`3
    extends System.Delegate
{
 .method public hidebysig newslot virtual
     instance void Invoke(!0 argA,
                !1 argB,
                !2 argC)
}
[C#]
public delegate void Action
           (A argA,
           B argB,
           C argC
           );
Assembly Info:
• Name:
• Public Key:
• Version:
© ISO/IEC 2006 – All rights reserved 5

---------------------- Page: 11 ----------------------
ISO/IEC TR 25438:2006(E)
• Attributes:
o CLSCompliantAttribute(true)
Implements:
• System.ICloneable
Summary:
Represents a method that performs an action using the supplied arguments.
Parameters:
Parameter Description
argA
The first argument to the action.
argB
The second argument to the action.
argC
The third argument to the action.

Inherits From: System.Delegate

Library: BCL

Description
A generic delegate type for three-argument methods, which perform an action (return void).
4.4 System.Action delegate
[ILAsm]
.class public auto ansi sealed System.Action`4
    extends System.Delegate
{
 .method public hidebysig newslot virtual
     instance void Invoke(!0 argA,
                !1 argB,
                !2 argC,
                !3 argD)
}
[C#]
public delegate void Action
           (A argA,
           B argB,
           C argC,
           D argD
           );
6 © ISO/IEC 2006 – All rights reserved

---------------------- Page: 12 ----------------------
ISO/IEC TR 25438:2006(E)
Assembly Info:
• Name:
• Public Key:
• Version:
• Attributes:
o CLSCompliantAttribute(true)
Implements:
• System.ICloneable
Summary:
Represents a method that performs an action using the supplied arguments.
Parameters:
Parameter Description
argA The first argument to the action.
argB
The second argument to the action.
argC
The third argument to the action.
argD
The fourth argument to the action.

Inherits From: System.Delegate

Library: BCL

Description
A generic delegate type for four-argument methods, which perform an action (return void).
© ISO/IEC 2006 – All rights reserved 7

---------------------- Page: 13 ----------------------
ISO/IEC TR 25438:2006(E)
4.5 System.Action delegate
[ILAsm]
.class public auto ansi sealed System.Action`5
    extends System.Delegate
{
 .method public hidebysig newslot virtual
     instance void Invoke(!0 argA,
                !1 argB,
                !2 argC,
                !3 argD,
                !4 argE)
}
[C#]
public delegate void Action
           (A argA,
           B argB,
           C argC,
           D argD,
           E argE
           );
Assembly Info:
• Name:
• Public Key:
• Version:
• Attributes:
o CLSCompliantAttribute(true)
Implements:
• System.ICloneable
Summary:
Represents a method that performs an action using the supplied arguments.
8 © ISO/IEC 2006 – All rights reserved

---------------------- Page: 14 ----------------------
ISO/IEC TR 25438:2006(E)
Parameters:
Parameter Description
argA The first argument to the action.
argB The second argument to the action.
argC The third argument to the action.
argD The fourth argument to the action.
argE The fifth argument to the action.

Inherits From: System.Delegate

Library:
...

TECHNICAL ISO/IEC
REPORT TR
25438
First edition
2006-08-01

Information technology — Common
Language Infrastructure (CLI) —
Technical Report: Common Generics
Technologies de l'information — Infrastructure commune de
langage (ICL) — Rapport technique: Génériques communs




Reference number
ISO/IEC TR 25438:2006(E)
©
ISO/IEC 2006

---------------------- Page: 1 ----------------------
ISO/IEC TR 25438:2006(E)

PDF disclaimer
PDF files may contain embedded typefaces. In accordance with Adobe's licensing policy, such files 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 the editing. In
downloading a PDF file, parties accept therein the responsibility of not infringing Adobe's 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 the PDF file(s) constituting this document can be found in the General Info relative to
the file(s); the PDF-creation parameters were optimized for printing. Every care has been taken to ensure that the files are suitable for
use by ISO member bodies. In the unlikely event that a problem relating to them is found, please inform the Central Secretariat at the
address given below.

This CD-ROM contains:
1) the publication ISO/IEC TR 25438:2006 in portable document format (PDF), which can be viewed
using Adobe® Acrobat® Reader; and
2) the electronic attachment CommonGenericsLibrary.cs, a reference implementation written in C#.
Adobe and Acrobat are trademarks of Adobe Systems Incorporated.



©  ISO/IEC 2006
All rights reserved. Unless otherwise specified, no part of this CD-ROM may be reproduced, stored in a retrieval system or transmitted in
any form or by any means without prior permission from ISO. Requests for permission to reproduce this product should be addressed to
ISO copyright office • Case postale 56
...

Questions, Comments and Discussion

Ask us and Technical Secretary will try to provide an answer. You can facilitate discussion about the standard in here.