Skip to content

Commit c208668

Browse files
authored
Merge pull request #150 from certik/fixes
Use 75 characters
2 parents 490e3cc + 261c5c6 commit c208668

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1-
To: J3
1+
To: J3 J3/20-109
22
From: Brad Richardson
33
Subject: Traits for Types
4-
Date: 2020-January-27
4+
Date: 2020-February-23
55

66
Proposal for Fortran Standard: 202y (NOT 202x)
77

88
1. Problem
99

1010
Currently, in order to pass a derived type to some library expected a type
11-
derived from it's own abstract type requires the addition of a "wrapper" type
12-
to be used. This requires a cumbersome amount of boiler plate code and is
13-
not conducive to the type of "generic" code one would like to be able to write.
11+
derived from it's own abstract type requires the addition of a "wrapper"
12+
type to be used. This requires a cumbersome amount of boiler plate code and
13+
is not conducive to the type of "generic" code one would like to be able to
14+
write.
1415

15-
This proposal seeks to address the issue that writing "generic" libraries is
16-
either not possible, or places undue burden on its users. The main benefits are
17-
the reduction in repeated logic or boiler plate wrapper types required for
18-
generic libraries, thereby enabling more code reuse and easier to maintain
19-
code bases.
16+
This proposal seeks to address the issue that writing "generic" libraries
17+
is either not possible, or places undue burden on its users. The main
18+
benefits are the reduction in repeated logic or boiler plate wrapper types
19+
required for generic libraries, thereby enabling more code reuse and easier
20+
to maintain code bases.
2021

2122
2. Proposed Solution
2223

2324
The solution would require the addition of a few attributes and variable
24-
declaration capabilities. First is the addition of the `trait` attribute
25-
to a type specification. This requires that the type be abstract, and contain
25+
declaration capabilities. First is the addition of the `trait` attribute to
26+
a type specification. This requires that the type be abstract, and contain
2627
no components. I.e.
2728

2829
type, abstract, trait :: Show_t
@@ -37,10 +38,10 @@ no components. I.e.
3738
end function show_i
3839
end interface
3940

40-
Second is the addition of the `implements` attribute for a type specification.
41-
The `implements` attribute requires a list of at least one trait the type is to
42-
implement, requiring the type to contain the procedures with the interfaces
43-
defined by the trait(s). I.e.
41+
Second is the addition of the `implements` attribute for a type
42+
specification. The `implements` attribute requires a list of at least one
43+
trait the type is to implement, requiring the type to contain the
44+
procedures with the interfaces defined by the trait(s). I.e.
4445

4546
type, implements(Show_t) :: Thing_t
4647
character(len=:), allocatable :: the_string
@@ -55,13 +56,14 @@ defined by the trait(s). I.e.
5556
string = self%the_string
5657
end function show
5758

58-
Third is the addition of a variable declaration form using `trait`, in a similar
59-
fashion to `class`. The `trait` specification would require a list of at least
60-
one trait, and must either be allocatable, or a dummy argument of a procedure.
61-
In a similar manner that the instantiated value of a class variable must be of
62-
that type, or an extended type, the instantiated value of a trait variable must
63-
be of a type which implements the given trait(s). Thus, no components of the
64-
instantiated value are accessible, only the procedures defined by the trait(s).
59+
Third is the addition of a variable declaration form using `trait`, in a
60+
similar fashion to `class`. The `trait` specification would require a list
61+
of at least one trait, and must either be allocatable, or a dummy argument
62+
of a procedure. In a similar manner that the instantiated value of a class
63+
variable must be of that type, or an extended type, the instantiated value
64+
of a trait variable must be of a type which implements the given trait(s).
65+
Thus, no components of the instantiated value are accessible, only the
66+
procedures defined by the trait(s).
6567

6668
3. Backward compatibility
6769

@@ -73,3 +75,5 @@ compatibility.
7375

7476
Online discussion that led to this proposal can be found at
7577
https://github.com/j3-fortran/fortran_proposals/issues/125
78+
79+

0 commit comments

Comments
 (0)