-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic Programming: modules parameterized over other modules #74
Comments
I do not think this solution is good or generic at all. So what is required from the programmer is to have a module with derived type called in a particular way (ELEMENT). What about a list of integers? What if we have an arbitrary type where we do not control how type is called? Create a wrapper module like: MODULE WRAPPER
USE MYTYPE2, ONLY: ELEMENT => WHATEVERNAMEWAS
END MODULE What if I want to use the list for some higher generic container? How do we then ensure that the module has type called I am against half-baked solutions that in 20 years everyone will hate but they will stay in the language forever because "backwards compatibility". First of all, what do we need the generic programming for? We won't have it for everything unless full-blown C++-like tempates are implemented. Do we need it to create linked lists and containers? I think they should be provided by the language. Do we need it to write one code for any kind of real/integer? Then probably we need something better than parametrized derived types that do not solve any problem. I think some realistic use cases from the industry should be taken. Everyone seems to be keen on writing containers (as they are missing from the language currently) but the truth is that should not even be the basic use case. So what else? |
I did not mean to be disrespectful. What I meant was that i thought this solution was very specific (similarly to parametrized derived types). |
I did not ask for this idea to be a top-level issue and I'm not going to waste time defending it. |
@septcolor thank you. @gronki yes, next time please try to formulate exactly the same point in a nicer way. Instead of saying:
You can say:
There are other ways to say it also. That way you still say exactly what you wanted to point out, and without risking of offending anyone, or putting anybody on the defense. We are all on the same team, and we have to trust each other that none of us wants to introduce some half-baked solutions into Fortran. I really appreciate that you are participating here, and I am actually in the same camp as you are --- I think it's better if we can figure out how to put features into the language itself (such as arrays which are already in Fortran), as opposed to making the language more general like C++ that does not have arrays and as a consequence there are dozens of incompatible array implementations. However there are other valid points of views. It's not black and white. |
I put this as a top level issue as I think it's worth discussing because it's an interesting idea. Thank you for contributing it. I am sorry some of the discussion wasn't the nicest, we will do better the next time. |
I think this is an idea worth trying to flesh out. It seems to me you wouldn't want to restrict it to only be parameterized by other modules, because it implicitly couples other modules to the parameterized one. I.e. the module cannot be used if it doesn't conform to the "interface" the parameterized one expects, but this isn't made explicit anywhere. However, treating it like a preprocessor type feature that only operates at the source code level might be able to get you far enough. This all needs more thought. |
Here is a draft proposal.
This proposal defines a means by which modules may be parameterized and instantiated upon
An optional module-dummy-list is added to module-stmt; module-name is
C1404: "module-name shall be the name of an intrinsic module" shall be changed C1405: "module-name shall be the name of a nonintrinsic module" shall be changed 14.2.2 paragraph 3, change "If the module-name is the name of both..." to read
(R1405) The module-dummy-names of a module-dummy-list shall be pairwise distinct. (R1405) In a module-dummy-list, a module-dummy-name in a default-module-spec shall (The usual positional and keyword-matching association scheme of Fortran applies
A module with no module-dummy-list constitutes its own instantiation. For each distinct instantiation of a module, there is corresponding instantiation A module-spec in a use-stmt constitutes a reference to an instantiation of a module. A module instantiation shall not reference itself directly or indirectly.
|
I proposed a general facility for parameterized modules in 2004. The J3 paper was 04-383r1. I think it does what Klausler asked for. It does what Magne Haveraaen asked for in Tokyo. |
A variation on this idea seems attractive to me, so I'll jot it down here rather than forget it. Fortran can support genericity with its current modules by using them as paradigms. For example, to define a generic linked list container, one would first write a model implementation with a fairly empty derived type for the payload in each node. This module would be compilable and testable, and would fully describe all of the requirements on the payload type. Then, to build a linked list of some specific type, one would reinstantiate the paradigmatic module with a type substitution. The replacement type must support all of the interfaces published for the payload type in the paradigm, and this would be checked. Substitution of types and parameters (or just their values) in paradigmatic modules would solve the most pressing use cases for generic programming that have been put forward, and would avoid a need for "requirements" or "concepts". |
@klausler suggested in #4 (comment):
From an implementation perspective, the form of polymorphism that I think would solve the most use cases with the least compiler grief would be modules parameterized over other modules, with explicit instantiation.
The text was updated successfully, but these errors were encountered: