J3/13-220
To: J3
From: Van Snyder
Subject: New types, not type aliases, from existing types
Date: 2013 December 20
Reference: 04-146r1; 2004 hate-dislike-like-love score 0-1-9-1
Title: New types, not type aliases, from existing types
Submitted by: Van Snyder
Status: For consideration
Basic functionality: Provide a facility to define new types, not type
aliases, from existing types.
Rationale: New types can be used for all purposes for which type aliases
are desired, but there are many things a new type can do that a type
alias cannot.
Here's one example where a new type solves a problem and a type alias
doesn't. Suppose you have the requirement to evaluate something using,
say, rational approximations, and in some cases you need six digits of
precision while in other cases you need twelve. Assume the twelve-digit
case is sufficiently more expensive that you want to use the six-digit
version where possible. With two routines, you use SELECTED_REAL_KIND
to declare their characteristics, and glue them together with a generic
name. You develop and certify them on a 32-bit machine. Then you send
your whole program off to production and they can't even compile it
because they use a 64-bit machine where SELECTED_REAL_KIND(6) and
SELECTED_REAL_KIND(12) are the same kind.
Estimated impact: Minor
Markham M6 conformance: New feature.
Detailed specification: Provide syntax to define a new type in terms of
an existing one. The type from which new types are created is
compatible with those types. New types inherit operations and
type-bound procedures from the type from which they are created.
Draft edits: To estimate scope of project
The strategy is to bootstrap on type extension. A new type is
effectively a type extension with no new components, no new procedure
bindings, and no new parameters. In fact, one can specify values for
parameters of the type upon which the new one is based, thereby reducing
the number of parameters that can be specified in an object declaration.
Insert an alternative to R207 :
"R207 <>
<> ...
<>
"
Insert a subclause after 4.5:
"<<4.5a New types created from existing types>>
"New types may be created from existing types. A type is type
compatible with all types created from it. Operations, assignment,
generic procedures, and procedure bindings of the type from which it
is created are available for new types created from it.
"R457a <> TYPE ::
R457b <> =>
"C498a (R457b) A in shall not be an
asterisk.
"If specifies a value for a type parameter, the new type has
that value for that type parameter. The type parameter order of the new
type includes type parameters specified by a colon and excludes type
parameters for which values are specified in . The value of
a type parameter specified by a value in is the value of
that type parameter for objects of type ; it can be
inquired for an object of type .
"NOTE 4.63a
For example
TYPE :: REAL_12 => REAL(selected_real_kind(12))
defines a new type REAL_12 for which the kind type parameter value is
selected_real_kind(12). Intrinsic arithmetic operations are available
for objects of type(REAL_12). Generic procedures with arguments of
type and kind REAL(selected_real_kind(12)) are available for objects
of type(REAL_12) unless specific procedures with type(REAL_12) are
available for the same generic identifier. If X is an object declared
TYPE(REAL_12) :: X
the value of KIND(X) is the value of selected_real_kind(12).
"
Within C483 insert "or new type" after "derived type".
Insert constraint C484a
"C484a (R453) If is a new type, a shall not
be specified for a type parameter value for which a value is
specified by the in its .
"
Within C485, replace "If a type parameter..." by "Except within a
, if a type parameter...".